What to do? lock()? invoke()? begininvoke()?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: David Logan (djlogan2_at_comcast.net)
Date: 05/25/04


Date: Tue, 25 May 2004 12:18:17 GMT

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



Relevant Pages

  • Re: Whats the best way to send and receive msg with worker threads?
    ... >comment it then the cdialog doesn't appear. ... >cdialog and I would pass a pointer "this", but in the worker thread ... If this is not executing in your main GUI thread, ... Note that you cannot use a worker thread for sockets, ...
    (microsoft.public.vc.mfc)
  • Re: socket communication / callback
    ... > I'm wondering if it's possible to use sockets for the folloing purpose: ... > A running process acts as a kind of server, ... > The receiving should trigger some functions (some display update based on ... toolkits provide an event loop already; if not then there are systems on ...
    (comp.lang.perl.misc)
  • Re: Subprocess with a Python Session?
    ... This is one of the more reliable methods since upon receiving a packet ... Using the readline method on file objects created from sockets ... flush(), if you want to do many records, or closeas Fredrik said if only one ...
    (comp.lang.python)
  • User defined messages to the Document
    ... I have an MDI application which has a socket receiving data. ... A worker thread that sits there and every second checks all ... (Actually call UpdateAllviews() ... all have the message handler in the CView class to which the hWnd ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Threading question
    ... As new data is received on the com port, ... I've tried setting the worker thread as a background thread and a foreground ... -- Shut down the thread receiving the data before you actually close the form (for example, override OnClose() and shut down the thread in that method, not returning from the method until you're sure the thread has exited) ...
    (microsoft.public.dotnet.languages.csharp)