Form.Show error within a Thread

  • Thread starter Thread starter Julia Chen
  • Start date Start date
J

Julia Chen

I have an application that has a thread which listens to a port for incoming
messages. The thread is declared and started in my main form, that is
opened from my sub main. In this thread, when a message has an ID in it, i
want a new form to show. I currently do this within the thread:

gContactForm = New frmContact(ID)
gContactForm.MdiParent = gMainForm.ActiveForm
gContactForm.Show()

But on the gContactForm.Show(), the form appears to 'hang' as a white
window.

Why is this happening, and more importantly, how can i fix it?
 
Julia Chen said:
I have an application that has a thread which listens to a port for
incoming messages. The thread is declared and started in my main form,
that is opened from my sub main. In this thread, when a message has an ID
in it, i want a new form to show. I currently do this within the thread:

Always create your forms in your application's main UI thread. Instance
members of Windows Forms forms and controls are not safe for multithreading,
so accessing them directly can cause problems. In addition to that, your
forms need a message pump which is normally provided by the app's main UI
thread.

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
 
Back
Top