摘要:EventWaitHandle.OpenExisting()和MemoryMappedFile.OpenExisting()都失败了,但仅在一台PC中失败了。
详细信息:我有一个程序使用EventWaitHandle来允许客户端C#对象等待工作对象更新通过MMF共享的某些数据。该程序可能已安装在一百台Win 7和Win 10 PC上。在客户提供的用于测试的一台臭味PC上,每张 exp 上的效果都很好。Acer Aspine V5 AMD A6-1450 1Ghz Win10 Home x64。
这是在客户端对象中创建EventWaitHandle的代码...
var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
// Rule that allows anybody in the "Users" group to synchronize with us...
var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);
var security = new EventWaitHandleSecurity();
security.AddAccessRule(rule);
Boolean created;
eventWaitHandleForCommands = new EventWaitHandle(
true,
EventResetMode.ManualReset, // Ignored. This instance doesn't reset.
"MyEventWaitHandle78AEE98", // Unique name
out created,
security
);
这是在辅助对象中打开EventWaitHandle的代码...
handleDomeCommand = EventWaitHandle.OpenExisting("MyEventWaitHandle78AEE98");
这是在Acer Aspine计算机上运行时在该行上发生的异常...
Exception = WaitHandleCannotBeOpenedException
Message = "No handle of the given name exists"
HResult = 8013152C
现在它变得更有趣了……还记得我提到过使用MMF吗?因此,我注释掉了EventWaitHandle.OpenExisting(),以便可以通过以下调用继续使用worker对象打开MMF ...
memMappedFile = MemoryMappedFile.OpenExisting("MyMMF_78AEE98", MemoryMappedFileRights.ReadWrite);
然后炸毁,但以下情况除外,但仅在此PC上(大约一百次安装就可以了!)...
Exception = System.IO.FileNotFoundException
Message = "Unable to find the specified file"
HResult = 80070002
顺便说一下,MMF是在客户端对象中创建的,如下所示...
MemoryMappedFileSecurity CustomSecurity = new MemoryMappedFileSecurity();
CustomSecurity.AddAccessRule(new
AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, AccessControlType.Allow));
mmfDome = MemoryMappedFile.CreateNew("MyMMF_78AEE98", MMF_CommandOffsets.MMF_Size,
MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, CustomSecurity, System.IO.HandleInheritability.Inheritable);
因此,这台PC似乎是不兼容的,但我已经了解了一个客户是否会遇到其他客户的问题。
我尝试过的其他事情...
因此,正在寻找建议/想法。谢谢! /克里斯