CloseHandle(IntPtr handle)抛异常

        [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool CloseHandle(IntPtr handle);

        [DllImport("kernel32", EntryPoint = "GetLastError")]
        public static extern int GetLastError();

 

CloseHandle()释放两次就会抛异常,用GetLastError()来捕获,如果返回3,3-系统找不到指定的路径。

解决办法:

CloseHandle(m_hSharedMemoryFile);
m_hSharedMemoryFile = IntPtr.Zero;

 

posted @ 2013-09-26 11:47  亲福  阅读(961)  评论(0编辑  收藏  举报