Is there a Form.Invoke() method?
- by rubicon
Hi,
I am new to multithreading (and also to C#) so I hope this is not obvious:
In my Form (WinForms application, .NET 2.0) I subscribed to an event that is raised by another object, and on handling this event I wish to change several Controls on my Form. As this event is raised in another thread than the main (UI) thread I want to marshal the call to the Form's thread.
I understand I could use the Control.Invoke() method on any Control that I want to change, but as there are several of them I do not wish to do that.
When searching the internet I found hints that the Form class itself provides an Invoke() method. See for example:
http://marioschneider.blogspot.com/2008/04/invoke-methode-fr-multithread.html
(Sorry, as I am I new user I can't seem to post more than one link. I will add more links as comments if possible.)
With that, I could just wrap my event handler and then use it as if it was called on the UI thread. However, this doesn't seem to be defined in my environment, and in MSDN's System.Windows.Forms.Form documentation there's also no sign of it.
Does this method exist in the .NET-Framework? I find it hard to believe that Form would not supply such a method, as it uses the same message queue the Controls on it do. (Or am I missing something here?)