0
我嘗試寫與Kinect的WPF應用程序,所以我必須寫這樣的代碼:當我嘗試執行該代碼 this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
, 我有這樣的錯誤如何使用委託BackgroundWorker?
static BackgroundWorker _bw = new BackgroundWorker();
_bw.DoWork += bw_DoWork;
_bw.RunWorkerAsync();
dispatcherTimerGame = new System.Windows.Threading.DispatcherTimer();
dispatcherTimerGame.Tick += new EventHandler(dispatcher_VerificaCarte);
dispatcherTimerGame.Interval = new TimeSpan(0, 0, 1);
dispatcherTimerGame.Start();
void bw_DoWork(object sender, DoWorkEventArgs e)
{
try
{
this.sensorChooser = new KinectSensorChooser();
this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
this.sensorChooser.Start();
this.sensor = this.sensorChooser.Kinect;
if (this.sensor != null)
{
DateTime dat1 = DateTime.Now;
string date = DateTime.Now.ToString("dd-MMM-yy HH-mm");
acquisizioneVideo = new Acquisizione("Video" + date + ".avi");
this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
acquisizioneAudio = new AcquisizioneWaveAudio(180, this.sensor, "Audio" + date + ".wav"); acquisizioneAudio.recordAudio();
acquisizioneVideo.recordVideo();
this.sensor.ColorFrameReady += acquisizioneVideo.ColorImageReady;
}
}
catch (Exception exc)
{
log.Error(exc);
}
}
所以:
[System.InvalidOperationException] = {"The calling thread cannot access this object because a different thread owns it."}"
我該如何解決它?
好的,謝謝,但我已經使用BackgroundWorker,因爲我想在Kinect初始化時執行其他代碼。如果我在main方法中編寫此代碼,我沒有AsyncTask – bircastri
,如果可能的話,您可能會執行其他代碼異步。 – pushpraj