Net.Pkcs11Interop.HighLevelAPI.Pkcs11.WaitForSlotEvent C# (CSharp) Method

WaitForSlotEvent() public method

Waits for a slot event, such as token insertion or token removal, to occur
public WaitForSlotEvent ( bool dontBlock, bool &eventOccured, ulong &slotId ) : void
dontBlock bool Flag indicating that method should not block until an event occurs - it should return immediately instead. See PKCS#11 standard for full explanation.
eventOccured bool Flag indicating whether event occured
slotId ulong PKCS#11 handle of slot that the event occurred in
return void
        public void WaitForSlotEvent(bool dontBlock, out bool eventOccured, out ulong slotId)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            if (Platform.UnmanagedLongSize == 4)
            {
                uint uintSlotId = CK.CK_INVALID_HANDLE;

                if (Platform.StructPackingSize == 0)
                    _p11_40.WaitForSlotEvent(dontBlock, out eventOccured, out uintSlotId);
                else
                    _p11_41.WaitForSlotEvent(dontBlock, out eventOccured, out uintSlotId);
                
                slotId = uintSlotId;
            }
            else
            {
                if (Platform.StructPackingSize == 0)
                    _p11_80.WaitForSlotEvent(dontBlock, out eventOccured, out slotId);
                else
                    _p11_81.WaitForSlotEvent(dontBlock, out eventOccured, out slotId);
            }
        }

Usage Example

 public void _03_WaitForSlotEventTest()
 {
     using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.UseOsLocking))
     {
         // Wait for a slot event
         bool eventOccured = false;
         ulong slotId = 0;
         pkcs11.WaitForSlotEvent(true, out eventOccured, out slotId);
         Assert.IsFalse(eventOccured);
     }
 }