Does a System.Windows.Threading.Dispatcher
work on the UI-thread of a WinForms
application?
If yes, why? It is coming from WindowsBase.dll which seems to be a WPF
component.
If not, how can I invoke work units back onto the UI-thread? I've found Control.BeginInvoke()
, but it seems clumsy to create a control only to reference the originating thread.
Sometimes a Timer component is useful and easy to setup in WinForms, just set its interval and then enable it, then make sure the first thing you do in its Tick event handler is to disable itself.
I think Timer runs the code in its own thread, so you may still need to do a BeginInvoke (called upon the WinForm object [this]) to run your Action.
you can see the above in action at WebCapture tool (http://gallery.clipflair.net/WebCapture, source code at: http://ClipFlair.codeplex.com, see Tools/WebCapture folder) that grabs screenshots from websites. BTW, if you want to call the executable from command-line make sure you go to Properties of the project and at Security tab turn-off ClickOnce security (else it can't access command-line)