D
David Logan
I have an application using sockets, and it uses the asynchronous method
for receiving (and others, but receiving is the basic problem.)
In short, I want:
class someClass: Form
{
mySocketClass sss;
...
sss.ReceivedData += myHandler
...
myHandler(String data) {
do cool stuff
}
}
The question is, in "mySocketClass", what is the best way to send an
event to the main class? Currently I am using the default event handling
stuff, but I am pretty certain that "myHandler" is being called
asynchronously without any thread protection (i.e. locking)
I don't really care if the socket implentation sends events
synchronously or asynchronously, so long as when "someClass" gets the
event, it is synchronous with respect to itself, it's own thread, and
whatever else may be going on there (it's a form, so mouse clicks for
example.)
I have not really found anything yet that gives me a good explanation of
Invoke(), Begin/End/Invoke(), lock(), etc.
What is the best way to send events from a worker thread to the main
thread? Or what is the best way for a class in a worker class to call
the main class/main thread event handlers?
David Logan
for receiving (and others, but receiving is the basic problem.)
In short, I want:
class someClass: Form
{
mySocketClass sss;
...
sss.ReceivedData += myHandler
...
myHandler(String data) {
do cool stuff
}
}
The question is, in "mySocketClass", what is the best way to send an
event to the main class? Currently I am using the default event handling
stuff, but I am pretty certain that "myHandler" is being called
asynchronously without any thread protection (i.e. locking)
I don't really care if the socket implentation sends events
synchronously or asynchronously, so long as when "someClass" gets the
event, it is synchronous with respect to itself, it's own thread, and
whatever else may be going on there (it's a form, so mouse clicks for
example.)
I have not really found anything yet that gives me a good explanation of
Invoke(), Begin/End/Invoke(), lock(), etc.
What is the best way to send events from a worker thread to the main
thread? Or what is the best way for a class in a worker class to call
the main class/main thread event handlers?
David Logan