Windows Form and controls needs to be created on UI thread or a thread which pump messages. Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread.
We can use the following code to Invoke the call ( which marshal the call to the UI thread) to open the form from non UI threads.
Delegate Sub ProcessForm(ByVal [text] As String)
Dim delegatetoProcessForm As New ProcessForm(AddressOf ProcessStopaRequest)
Application.OpenForms(0).Invoke(delegatetoProcessForm, New Object() {["text"]})
How to: Make Thread-Safe Calls to Windows Forms Controls
http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment