我目前正在開發一個帶有c#和.net框架4.5的windows服務來擴展現有專有應用程序的功能,這個服務在EventWaitHandleClass(msdn link)上等待從主應用程序發出的命名事件。事情是這樣的:使用EventWaitHandle等待命名事件的Windows服務問題。
bool boolWithFalse = false;
string eName = "notification_event";
string usr = Environment.UserDomainName + "\\" + Environment.UserName;
EventWaitHandleSecurity security = new EventWaitHandleSecurity(); //*
EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(usr, EventWaitHandleRights.Synchronize, AccessControlType.Allow);
security.AddAccessRule(rule);
EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset, eName, out boolWithFalse, security);
//... some non relevant code lines here
//This is where the it locks waiting for the named event
var w = EventWaitHandle.WaitAny(new[] { handle }, Timeout.Infinite);
*:EventWaitHandleSecurity MSDN
現在,這就像如果我執行我的程序作爲控制檯應用程序,我可以很容易地從主應用程序趕上事件和處理它們,因爲我打算魅力,但是,當我將應用程序安裝爲服務時,它會鎖定等待這個相同的命名事件,但從未收到信號。該服務設置爲使用NT AUTHORITY \ LOCALSERVICE帳戶運行,我已經嘗試使用我自己的帳戶(程序運行時用作控制檯應用程序),但沒有任何反應。
如果它有助於發起信號的應用程序在我自己的帳戶下運行。我非常感謝任何幫助,因爲我是一個爲Windows開發桌面應用程序的完整初學者。
歡迎來到堆棧溢出,我已編輯您的問題,請參閱http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles –
好的,謝謝。 – George181716