Hi all
I am trying to speed up my silver light app which uses a web cam, as I don't like the way it displays a jittery display while processing an image
Up until now I have used a timer and processed an image every 250 m/s
let me try and explain with a bit of code
public void StartTimer() { myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 250); myDispatcherTimer.Tick += new EventHandler(Each_Tick); myDispatcherTimer.Start(); }
Then in my 'Each_Tick'
public void Each_Tick(object o, EventArgs sender) { if (_captureSource.State == CaptureState.Started) { try { //Grab a frame from the stream ExtendedImage ExtImage = new ExtendedImage(WebcamCapture.ToImage()); ProcessImage(ExtImage); } catch (Exception ex) { exception = ex; } } }
OK so this works but its slow, so I'm going to use ThreadPool
So now what I want to do is to call the threadpool
public void Each_Tick(object o, EventArgs sender) { ThreadPool.QueueUserWorkItem(new WaitCallback(myThread)); }
And define a new method like so:
public void myThread(object a) { if (_captureSource.State == CaptureState.Started) { try { //Grab a frame from the stream ExtendedImage ExtImage = new ExtendedImage(WebcamCapture.ToImage()); ProcessImage(ExtImage); } catch (Exception ex) { exception = ex; } } }
But when I do this I'm getting an error “invalid cross thread access when using threadpool”
I've tried adding Thread.sleep at the end of the Thread method but still dont work
Any Ideas as to how I can fix it