Creating Win32 events from c#

╄→гoц情女王★ 提交于 2019-12-03 11:13:10

Take a look at the EventWaitHandle class. It's supported from .Net 2.0 onwards and allows creation of named events. It also supports setting event security, depending on which constructor you use.

If you still want to use interop, you can define the function like this:

[DllImport("kernel32.dll")]
static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);

and the struct like this(you may have to mess with the Pack attribute to make it fit):

[StructLayout(LayoutKind.Sequential)]
struct SECURITY_ATTRIBUTES{
  public int length;
  public IntPtr securityDesc;
  public bool inherit;
}

Also, here's a code example of putting it all together.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!