Re: Synchronizing processes in C#

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

From: David Levine (noSpamdlevineNNTP2_at_wi.rr.com)
Date: 07/03/04


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!
> >
> >
> >



Relevant Pages

  • Re: Thread-safe fuctions
    ... Google research _seems_ to shows that reentrant is an older ... > for the second execution, another activation frame is created *on the ... > works correctly with many invocations on a single stack, ... a simple function that uses a mutex to ...
    (comp.unix.programmer)
  • Re: Thread safe logging (or protecting global variables)
    ... I would use the static mutex initializer macro on POSIX?". ... you can initialize a mutex with a static initializer (which ... condition on the other singleton. ... threads during dll static init, so I can simply use a naive eager- ...
    (comp.programming.threads)
  • Re: Boot Loader and bib file
    ... Even i thought that FlashNand is just to initialize the NAND/hardware ... the second portion to flash the regular bootloader into nand flash. ... BootStrap - Xloader program execution (copying from NAND flash to ... similar to actual boot loader(3rd step) in case of WinCE ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Application.Exit problem
    ... > I will check out the use of the Mutex method to prevent multiple instances. ... >> the System.Threading namespace) to keep multiple instances of your>> application from running. ... You should establish your database>> connection outside of the form constructor (before the Run method is ... >>> I need to abort execution during start up, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is this kosher...
    ... calls for "mutexes that are statically allocated" (Open Group ... You're trying to initialize an auto ... mutex and then copy it to a dynamically-allocated mutex, ... into the data cache and it would sometimes not be visible to the ...
    (comp.programming.threads)