dast <(E-Mail Removed)> wrote:
> I have a background thread that opens a form. But when that thread ends, the
> form I opened disappears. This makes me want the background thread to tell my
> main thread to open the form instead.
Yes - that would be a better idea. *All* UI work should be done on the
main UI thread.
> The form should be opened by my main thread when my communication thread
> receives a certain message. I?ve been trying to do this using delegates
> (whose existence just recently came to my knowledge), but I?m failing and
> have started wondering if it couldn?t be done using events instead.
>
> This is my scenario:
>
> StartForm (my main form)
> CommForm (handles my serial communication)
> FormA (I want StartForm to open this form)
>
> When data is available on my serialport, the sub below is run as a separate
> thread in my CommForm. When all data is read, the thread ends.
>
> Private Shared Sub ReceiveEvent(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles SerialPort.DataAvailable
> 'here I want to tell my main thread (StartForm) to open FormA
> End Sub
You need to use Control.Invoke here.
See
http://www.pobox.com/~skeet/csharp/t...winforms.shtml
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too