G
Guest
Hi,
I'm having trouble letting my background thread tell my main thread what to
do.
I'm trying to tell my main thread to open a form, but when my background
thread ends, the form that I thought my main thread had opened disappears.
Obviously there's something that I don't understand here.
The background thread is run in another class on another form. How do I,
from there, get my main thread to do something? 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
'this is how I try to do that
Dim del As Start.MyDelegate
del = New Start.MyDelegate(AddressOf Start.OpenFormA)
del.Invoke()
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 for any help on this.
I've been trying for days now...
/Daniel
I'm having trouble letting my background thread tell my main thread what to
do.
I'm trying to tell my main thread to open a form, but when my background
thread ends, the form that I thought my main thread had opened disappears.
Obviously there's something that I don't understand here.
The background thread is run in another class on another form. How do I,
from there, get my main thread to do something? 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
'this is how I try to do that
Dim del As Start.MyDelegate
del = New Start.MyDelegate(AddressOf Start.OpenFormA)
del.Invoke()
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 for any help on this.
I've been trying for days now...
/Daniel