예제 #1
0
        //Make the constructor private to hide it. This class adheres to the singleton pattern.
        private SmartcardManager()
        {
            //Create a new SafeHandle to store the smartcard context.
            this._context = new SmartcardContextSafeHandle();
            //Establish a context with the PC/SC resource manager.
            this.EstablishContext();

            //Compose a list of the card readers which are connected to the
            //system and which will be monitored.
            ArrayList availableReaders = this.ListReaders();

            this._states = new ReaderState[availableReaders.Count];
            for (int i = 0; i <= availableReaders.Count - 1; i++)
            {
                this._states[i].Reader = availableReaders[i].ToString();
            }

            //Start a background worker thread which monitors the specified
            //card readers.
            if ((availableReaders.Count > 0))
            {
                this._worker = new BackgroundWorker();
                this._worker.WorkerSupportsCancellation = true;
                this._worker.DoWork += WaitChangeStatus;
                this._worker.RunWorkerAsync();
            }
        }
 static internal extern uint ListReaders(SmartcardContextSafeHandle context, string groups,
                                         string readers, ref int size);
 static internal extern uint GetStatusChange([In(), Out()] SmartcardContextSafeHandle context,
                                             [In(), Out()] int timeout, [In(), Out()] ReaderState[] states, [In(), Out()] int count);
 static internal extern uint EstablishContext(ScopeOption scope, IntPtr reserved1,
                                              IntPtr reserved2, ref SmartcardContextSafeHandle context);