? WPF Graphical UI & Threads - Please help - Urgent! :(
-
Tuesday, March 18, 2008 3:31 PM
Hi
I have a wpf window that has a canvas and an image placed on the canvas.
In the code for this window I am using events mouse down, mouse up, and mouse move.
However, I also need to kick of a thread that every 1 seconds reports back to the ui thread with the current mouse position = I need to test when the mouse hasn't moved for a short period of time.
However, unlike in windows forms when I'd use the invoke.required on a text box or something with a delegate in order to post info back from the thread, in this case I know that wpf uses the dispatcher.invoke or .begininvoke, however I'm not UPDATING a UI Element - I'm trying to set booleans and pass in a mouse positions (as a point) back to the UI thread.
So can anyone please explain (simply) how to do this?
I've used the windows forms method for threads to update boxes and labels on the UI, but that 'approach' doesn't seem to be what I need to do in this case.
Any help?
Please - I need this figuring out today as I have a deadline to meet for my 3rd year project.
Thanks
Zoe
All Replies
-
Tuesday, March 18, 2008 4:39 PM
Bump!
- Proposed As Answer by narfzort Tuesday, September 02, 2008 6:45 PM
-
Tuesday, March 18, 2008 5:08 PM
myControl.Dispatcher.BeginInvoke(...)
Take a look at
Dispatcher.BeginInvoke http://msdn2.microsoft.com/en-us/library/ms591206.aspx
Or
DispatcherTimer http://msdn2.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx
--Ifeanyi Echeruo [MSFT] -
Tuesday, March 18, 2008 6:56 PM
Hi. As my post mentioned I'd already had a look at the Dispatcher.Invoke but couldn't work out how to use it in my example as no UI element had to be 'updated'.
However you are wonderful in knowing and suggesting the (heretofore unknown to me) DispatcherTimer - which is EXACTLY what I want to use!!!!
Awesome! Huge thanks to you.
However I need to use this in a time interval of around 1/10th down to 1/100th of a second, but the msdn example only gives lowest 1sec.
Any ideas?
Thanks so much...
Zoe
-
Tuesday, March 18, 2008 9:02 PM
DispatcherTimer.Interval is of type TimeSpan
TimeSpan has several convenience methods to create subsecond time spans.
For example http://msdn2.microsoft.com/en-us/library/system.timespan.frommilliseconds.aspx
--Ifeanyi Echeruo [MSFT]

