G
Guest
Hi,
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.
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
How should I solve this? Is an event more appropriate to use instead of a
delegate?
Iv'e been searching a bit on delegates and events, but I can't figure out
how to get them working between threads. All examples I've found are within
the same thread.
Many thanks in advance.
/Daniel
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.
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
How should I solve this? Is an event more appropriate to use instead of a
delegate?
Iv'e been searching a bit on delegates and events, but I can't figure out
how to get them working between threads. All examples I've found are within
the same thread.
Many thanks in advance.
/Daniel