Using threads 
Author Message
 Using threads

Hi,

I'm creating a thread and I want this thread to raise an event or send a
signal when it is finished. How can I do that?

Thanks
Erez

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 21 Nov 2004 15:37:45 GMT  
 Using threads
USe synchronization mechanizms, like Mutex


Sun, 21 Nov 2004 15:53:48 GMT  
 Using threads
Do you mean that the thread will hold the mutex and release it when it's
finished?
Isn't there any indication that the thread exited?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 21 Nov 2004 16:17:55 GMT  
 Using threads
Take a look at the ManualResetEvent class, here is a sample:

using System.Threading;
using System;
public class Queue{
 public  static ManualResetEvent[]    eventX;
  static void WorkerFunction(object obj)
  {
   String str=(String)obj;
   Console.WriteLine(str);

   if(str == "item1") {
    Thread.Sleep(5000);
    eventX[0].Set();  // Set event state to signaled
   }
   else {
    Thread.Sleep(2000);
    eventX[1].Set(); // Set event state to signaled
   }
  }

    static int Main(string[] args) {
  Queue q = new Queue();
  ManualResetEvent[]    eventX = new ManualResetEvent[2];
  Queue.eventX = eventX;
  Queue.eventX[0]  = new ManualResetEvent(false);  //Set initial state to nonsignaled
        ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerFunction),"item1");
  Queue.eventX[1]  = new ManualResetEvent(false);  // Set initial state to nonsignaled
        ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerFunction),"item2");
  // Wait for all events to be signaled
        WaitHandle.WaitAll(Queue.eventX,Timeout.Infinite,true);
        return 0;
 }

Quote:
}

Willy.
Quote:

> Hi,

> I'm creating a thread and I want this thread to raise an event or send a
> signal when it is finished. How can I do that?

> Thanks
> Erez

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Sun, 21 Nov 2004 17:03:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. HELP, PC Slows down, using Threads, DAO, DirectX Play

2. LNK 2001 error using threads

3. Should i be using threads ?

4. CSocket connect using Thread

5. Using Thread

6. Using Threads to alter Dialog box controls

7. Using Thread Local Storage in the common WNDPROC

8. Using Thread to create Watchdog

9. Writing code for two processors using threads

10. Debug assertion failed in SockCore when using threads

11. using threads in a dll

12. problem using thread/delegates

 

 
Powered by phpBB® Forum Software