FTD2XX_NET.FTDI.SetEventNotification C# (CSharp) Method

SetEventNotification() public method

Register for event notification.
After setting event notification, the event can be caught by executing the WaitOne() method of the EventWaitHandle. If multiple event types are being monitored, the event that fired can be determined from the GetEventType method.
public SetEventNotification ( UInt32 eventmask, EventWaitHandle eventhandle ) : FT_STATUS
eventmask System.UInt32 The type of events to signal. Can be any combination of the following: FT_EVENT_RXCHAR, FT_EVENT_MODEM_STATUS, FT_EVENT_LINE_STATUS
eventhandle System.Threading.EventWaitHandle Handle to the event that will receive the notification
return FT_STATUS
        public FT_STATUS SetEventNotification(UInt32 eventmask, EventWaitHandle eventhandle)
        {
            // Initialise ftStatus to something other than FT_OK
            FT_STATUS ftStatus = FT_STATUS.FT_OTHER_ERROR;

            // If the DLL hasn't been loaded, just return here
            if (hFTD2XXDLL == IntPtr.Zero)
                return ftStatus;

            // Check for our required function pointers being set up
            if (pFT_SetEventNotification != IntPtr.Zero)
            {
                tFT_SetEventNotification FT_SetEventNotification = (tFT_SetEventNotification)Marshal.GetDelegateForFunctionPointer(pFT_SetEventNotification, typeof(tFT_SetEventNotification));

                if (ftHandle != IntPtr.Zero)
                {
                    // Call FT_SetSetEventNotification
                    ftStatus = FT_SetEventNotification(ftHandle, eventmask, eventhandle.SafeWaitHandle);
                }
            }
            else
            {
                if (pFT_SetEventNotification == IntPtr.Zero)
                {
                    LogB.Debug("FTD2XX: Failed to load function FT_SetEventNotification.");
                }
            }
            return ftStatus;
        }