C#.NET Threading problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sampalmer21
    New Member
    • Feb 2008
    • 11

    C#.NET Threading problem.

    Hi,

    I have a c# threading question:

    I have a main thread which calls a child thread process. While the child thread is running the main thread works on tasks. Is it possible for the main thread to know as soon as the child thread has completed and then allow the main thread to perform a cleanup task before returning back to its regular tasks? What I don't want to do is childThread.joi n() as this would cause the main thread to wait for the child thread to finish. I just want to be signaled immediately after the child is finished so that I can perform cleanup and then continue with regular tasks.

    Thanks
    Sam Palmer,
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I have taken to using custom events to handle these things.
    Suppose everything you wanted the child thread to do, was incapsulated in a class.
    You would create an instance of that object on your main thread and be like "ok object, run your thread stuff"
    Now on that class, you would have created a custom event like "ThreadComplete d" or something. When you child thread is finishing up, it would trigger that event to fire.
    Your main thread, which has the instance of the object, would attach a listen to that event, and would thus get notified when the child thread was ending.

    Comment

    Working...