From 708c9134b28867e8d91d040e707ff604f41b0224 Mon Sep 17 00:00:00 2001 From: Jukka Hopeavuori Date: Sat, 12 Mar 2016 13:35:26 +0200 Subject: [PATCH 1/2] Call Thread.Start without the parameter in CardBase.StartCardEvents, because otherwise a System.InvalidOperationException is thrown. --- Smartcard_API/GemCard/CardBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Smartcard_API/GemCard/CardBase.cs b/Smartcard_API/GemCard/CardBase.cs index b834828..c298f77 100644 --- a/Smartcard_API/GemCard/CardBase.cs +++ b/Smartcard_API/GemCard/CardBase.cs @@ -124,7 +124,7 @@ public bool StartCardEvents(string Reader) m_bRunCardDetection = true; m_thread = new Thread(() => RunCardDetection(Reader)); - m_thread.Start(Reader); + m_thread.Start(); ret = true; } From 563120cb487770aea2290ad2e132a4628dc804cf Mon Sep 17 00:00:00 2001 From: Jukka Hopeavuori Date: Sun, 4 Mar 2018 15:05:24 +0200 Subject: [PATCH 2/2] Added support for multiple readers in CardBase --- Smartcard_API/GemCard/CardBase.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Smartcard_API/GemCard/CardBase.cs b/Smartcard_API/GemCard/CardBase.cs index c298f77..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 = 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