Re: Synchronizing processes in C#
From: David Levine (noSpamdlevineNNTP2_at_wi.rr.com)
Date: 07/03/04
- Next message: Chua Wen Ching: "RE: Performance is bad"
- Previous message: Chua Wen Ching: "Re: can ternary statements be nested?"
- In reply to: AKA COOPERMAN: "RE: Synchronizing processes in C#"
- Next in thread: Kieran Benton: "Re: Synchronizing processes in C#"
- Reply: Kieran Benton: "Re: Synchronizing processes in C#"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 3 Jul 2004 04:28:48 -0500
Those classes do not support named events which means they cannot be used
between processes.
"AKA COOPERMAN" <AKACOOPERMAN@discussions.microsoft.com> wrote in message
news:DAF12745-B109-4B29-A8B9-5FFD49D6DBF4@microsoft.com...
> Try using the following classes instead
>
> AutoResetEvent
> ManualResetEvent
>
> Andy Cooper
>
> "Chris B" wrote:
>
> > I have the following situation:
> >
> > Process 1 creates Process 2 (using Process.Start(startInfo)
> > Process 1 needs to wait until Process 2 is initialized before Process 1
can continue to execute
> > Both processes are non-GUI processes.
> >
> > The problem that I am running into is that the Process.Start(startInfo)
returns immediately to Process 1. Therefore, process 1 does not wait on its
own for Process 2 to initialize.
> >
> > Process 2 can take a few seconds to intialize. Process 1 needs to halt
its execution until Process 2 is initialized. How can process 1 and 2
signal eachother to accomplish what I'm after?
> >
> > In process 1 I tried using a Mutex:
> >
> > Process process = Process.Start(startInfo);
> >
> > if (process != null)
> > {
> > Mutex m = new Mutex(false, "Mutex");
> > m.WaitOne();
> > ...
> > }
> >
> > Process 2:
> >
> > Main...
> > {
> > bool mutexWasCreated = false;
> > Mutex m = new Mutex(true, "Mutex", out mutexWasCreated);
> > if (mutexWasCreated)
> > {
> > ...
> > m.ReleaseMutex();
> > }
> > }
> >
> > this doesn't come close to working because process 1 gets the mutex
before process 2 can acquire the lock. What I need is the ability to have
process 1 wait on a mutex, have process 2 acquire the mutex lock, do its
initialization, then release the mutex, then process 1 resumes execution.
> >
> > I have gotten the above to work in C++ using the CreateEvent API.
Process 1 creates an unsignaled event, process 1 launches process 2, process
1 waits on the event, process 2 does its thing, process 2 signals the event,
process 1 continues.
> >
> > How can I do this in C#?
> >
> > Thanks!
> >
> >
> >
- Next message: Chua Wen Ching: "RE: Performance is bad"
- Previous message: Chua Wen Ching: "Re: can ternary statements be nested?"
- In reply to: AKA COOPERMAN: "RE: Synchronizing processes in C#"
- Next in thread: Kieran Benton: "Re: Synchronizing processes in C#"
- Reply: Kieran Benton: "Re: Synchronizing processes in C#"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|