locked
EventWaitHandle synchronization between windows forms app and windows service RRS feed

  • Question

  • Hi everybody,

    I have two programs, that must 'talk' to one another (is that correct english - please forgive possible errors).
    One is a service, two a forms app that asks the service to do stuff. To make debugging easier, I started with two 'normal' programs, one playing the service part, two being two.
    Both were using the same code to access the EventWaitHandle :

    private const string readyName = "Company.Prog.ServiceReadyHandle";
    public static EventWaitHandle ready = new EventWaitHandle(false,
                                            EventResetMode.AutoReset,
                                            readyName);

    no problems, everything worked fine
    then I used the same code in my service, and it didn't work anymore:

    System.UnauthorizedAccessException: Access to the path '...' is denied.

    OK some googling later I come up with:

    private const string readyName = @"Global\Company.Prog.ServiceReadyHandle";

    - no change, then change prog two to:

    ready = EventWaitHandle.OpenExisting(readyName);

    - no change, then I went back two progs one and two (no service) and started one in admin context:
    - same problem as with service, so now I try:

                var ewhSec = new EventWaitHandleSecurity();
                var rule = new EventWaitHandleAccessRule("Everyone",
                                                         EventWaitHandleRights.Synchronize |
                                                         EventWaitHandleRights.Modify,
                                                         AccessControlType.Allow);
                ewhSec.AddAccessRule(rule);
                bool wasCreated;
                ready = new EventWaitHandle(false,
                                            EventResetMode.AutoReset,
                                            readyName,
                                            out wasCreated,
                                            ewhSec);

    - same problem

    then I started program two first (by error) and then prog one:

    - it works ????

    back to start one, then two : error

    after several hours I find :

    if I start a program with normal rights and then the other one with admin rights (or system rights as service) everything works fine
    the other way round (that's what I need) : error

    please help

    Tuesday, February 24, 2009 9:02 PM