Exception Filter

C# does not support exception filter. However, VB and IL support it. To add exception filter to C#, we can build a function in VB or IL, then call it in C#. The example below is one way we may implement the function to support exception filter. It asks the caller to provide four delegates,…

7

ThreadPool.BindHandle

I mentioned that we can use ThreadPool.BindHandle to implement asynchronous IO. Here are roughly the steps necessary to make it happen: 1.       Create an overlapped file handle             SafeFileHandle handle = CreateFile(                                 filename,                                 Win32.GENERIC_READ_ACCESS,                                 Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE | Win32.FILE_SHARE_DELETE,                                 (IntPtr)null,                                 Win32.OPEN_EXISTING,                                 Win32.FILE_FLAG_OVERLAPPED,                                 new SafeFileHandle(IntPtr.Zero, false));         [DllImport(“kernel32.dll”, CharSet…

8