Events abfangen



  • Hallo,

    ich habe ein Programm geschrieben (Visual Studio 2010), dass auf ein Event wartet und beim Eintreffen darauf reagiert. Das Event wird in einem alten Programm, welches mit Visual Studio 2003 geschrieben wurde, gesetzt. Jetzt ist es aber so, dass mein Programm auf dieses Event nicht reagieren kann. Ich bekomme die Fehlermeldeung, "dass ein Handle mit diesem Namen nicht existiert". Setze ich das Event in einem Programm, das ebenfalls mit dem 2010er Compiler erstellt wurde, dann funktioniert es. Ich denke, dass es an der Darstellung des Strings in Unicode (2010er Compiler) liegt und das Programm deswegen den Namen nicht erkennt.
    Gibt es eine Möglichkeit den String zu konvertieren, so dass es funktioniert? Oder eine andere Möglichkeit das Event abzufangen?
    Zur Zeit mache ich es so:

    private EventWaitHandle m_EWH = null;
      private const string STR_TestEvent = "Testevent";
      m_EWH = EventWaitHandle.OpenExisting(STR_TestEvent);
    

    Schon mal vielen Dank!!



  • Guck doch erstmal mit dem ProcessExplorer ob Du das Event (Kernel Objekt) findest.

    **Edit:**Und hier vermutlich die Lösung:
    http://blog.objectpattern.com/dot-net/ignorance-is-not-bliss-eventwaithandle-openexisting-throws-waithandlecannotbeopenedexception/



  • Hallo,

    Ich kann den Link hier im Betrieb leider nicht öffnen. Hast du noch einen anderen Link, in dem das Problem beschrieben wird oder kannst du mal versuchen, das Wichtigste kurz zusammenzufassen?



  • Blog Eintrag:

    Ignorance is not bliss. EventWaitHandle.OpenExisting throws WaitHandleCannotBeOpenedException
    Filed under: .NET, Windows Plateform — Himanshu @ 12:06 pm
    My development computer got upgraded to Windows 7, Windows 7 is good experience.

    For one of our client, I needed to setup mechanics such that admin users should be able to initiate a process in Windows Service using GDI based .NET application. We had also developed the windows service in .NET. As both of them are .NET applications, there are more than one ways to IPC between them. As in this case there was only need to give signal to the service, I choose to do it through Windows Event. .NET BCL provides wrapper around Win32 functions to do this through type named EventWaitHandle.

    I completed the code like I used to do in my old days, and tried the first use of it. On call to OpenExisting, client application failed with exception “No handle of the given name exists”. My first thought was that this could be because of UAC, but in that case it should say something like access violation. I tried running application in Windows 2003 Server and it worked perfectly. I decided to check with Google and documentation. I found this, which gave me a relieving thought – “I’m not the only one in this world!” .

    After some time I landed to msdn page for namespaces of kernel objects, which indicates that:

    For processes started under a client session, the system uses the session namespace by default. However, these processes can use the global namespace by prepending the “Global\” prefix to the object name

    changed my client code to have name prefixed with “Global\”, and everything started behaving the way I wanted it to in Windows 7 as well.

    http://social.msdn.microsoft.com/Forums/en/clr/thread/91810489-d932-4e4f-bbb7-4a5f02c39cf9
    http://msdn.microsoft.com/en-us/library/aa382954(VS.85).aspx



  • Ich habe mir das jetzt mal durchgelesen. Aber kann das jetzt nicht so wirklich auf mein Problem umsetzen.
    Oder ich habe da etwas missverstanden 😞



  • Oder ich habe da etwas missverstanden

    Kann ich nicht sagen, da ich nicht weiss was Du denkst verstanden zu haben.



  • für mich hat es sich so gelesen, dass das Problem dort darin bestand, dass es auf einem anderem Betriebssystem nicht funktioniert hat.

    Mein Problem besteht aber darin, dass es das Event nicht erkennt, weil das alte Programm in Multibytecode geschrieben ist und das neue Programm in Unicode. Weswegen das neue Programm den Namen des Events nicht erkennt, weil es die Strings nicht vergleichen kann. (Was sich in den letzten Stunden durch ständiges testen rauskristalisiert hat und ich im Ausgangsthread auch schon vermutet habe)

    Wir sind jetzt dabei das alte Programm so umzustricken, dass der Name des Events ebenfalls in Unicode ist. Dann wird es erkannt. Was aber auch problematisch ist, da es von meinem neuen Programm eine alte Version gibt, die auf das Event in Multibyte reagiert. Deswegen suche ich noch nach einer Lösung, mein Programm so abzuändern, dass ich auf das Event in Multibytecode reagieren kann. Bisher habe ich dazu noch nichts gefunden. Vielleicht weil ich die Suche auch falsch angegangen bin. Ich weiß es nicht.


Anmelden zum Antworten