diff --git a/Smartcard_API/GemCard/CardBase.cs b/Smartcard_API/GemCard/CardBase.cs index b834828..56c2171 100644 --- a/Smartcard_API/GemCard/CardBase.cs +++ b/Smartcard_API/GemCard/CardBase.cs @@ -63,7 +63,7 @@ abstract public class CardBase : ICard, IDisposable protected const uint WAIT_TIME = 250; protected bool m_bRunCardDetection = true; - protected Thread m_thread = null; + protected Dictionary m_threads = new Dictionary(); /// /// Event handler for the card insertion @@ -114,28 +114,45 @@ public virtual ControlResponse Control(IntPtr cardHandle, ControlCommand control /// /// This method should start a thread that checks for card insertion or removal /// - /// + /// /// true if the events have been started, false if they are already running - public bool StartCardEvents(string Reader) + public bool StartCardEvents(string reader) { bool ret = false; + + Thread m_thread; + m_threads.TryGetValue(reader, out m_thread); + if (m_thread == null) { m_bRunCardDetection = true; - m_thread = new Thread(() => RunCardDetection(Reader)); - m_thread.Start(Reader); + m_thread = new Thread(() => RunCardDetection(reader)); + m_thread.Start(); + + m_threads[reader] = m_thread; + ret = true; } return ret; } + public void StopCardEvents() + { + foreach (string reader in m_threads.Keys) + { + StopCardEvents(reader); + } + } + /// /// Stops the card events thread /// - public void StopCardEvents() + public void StopCardEvents(string reader) { + Thread m_thread = m_threads[reader]; + if (m_thread != null) { int