title: How to make RFID reader seek for card continously
body: <p>For a while now, i have been trying to make my RFID reader to automatically read (scan) a card. Although the former code i had, makes the reader scan the card when a button is pressed. But i want to be able to scan cards automatically and continuously, once any card is placed in the field. Here is what i tried. but i was not able to display the scanned UID in a textbox. Please, your help will be appreciated.</p>
  
  <pre><code> class CardReader : IDisposable
      {
  
          IntPtr _pSnr = Marshal.AllocHGlobal(1024);
          private Thread _t;
          private Action&lt;string&gt; _callback;
          private volatile bool _stop;
  
          public void ReadCard()
          {
              short icdev = 0x0000;
              int status;
              byte type = (byte)'A';//mifare one type is A 
              byte mode = 0x26;  // Request the card which is not halted.
              ushort TagType = 0;
              byte bcnt = 0x04;//mifare  hold on 4
              IntPtr pSnr;
              byte len = 255;
              sbyte size = 0;
              pSnr = Marshal.AllocHGlobal(1024);
              for (int i = 0; i &lt; 2; i++)
              {
                  status = rf_request(icdev, mode, ref TagType);//request card  
                  if (status != 0)
                      continue;
  
                  status = rf_anticoll(icdev, bcnt, pSnr, ref len);//i did anticol--get the card sn
                  if (status != 0)
                      continue;
  
                  status = rf_select(icdev, pSnr, len, ref size);//select one card
                  if (status != 0)
                      continue;
  
                  byte[] szBytes = new byte[len];
  
                  for (int j = 0; j &lt; len; j++)
                  {
                      szBytes[j] = Marshal.ReadByte(pSnr, j);
                  }
  
                  String m_cardNo = String.Empty;
  
                  for (int q = 0; q &lt; len; q++)
                  {
                      m_cardNo += byteHEX(szBytes[q]);
                  }
  
                  _callback(m_cardNo);
  
                 // txtSearchPurse.Text = m_cardNo;
  
                  break;
              }
          }
  
          public void Work()
          {
              while (!_stop)
              {
                  ReadCard();
                  Thread.Sleep(1000);
              }
          }
  
          public void Start(Action&lt;string&gt; cardRead)
          {
              if (_t != null)
                  return;
  
              _stop = false;
  
              _callback = cardRead;
  
              _t = new Thread(Work);
              _t.Start();
          }
  
          public void Stop()
          {
              if (_t != null)
              {
                  _stop = true;
                  _t.Join();
                  _t = null;
              }
          }
  
          public void Dispose()
          {
              Marshal.FreeHGlobal(_pSnr);
          }
      }
  </code></pre>
  
  <p>And i tried to use it like this:</p>
  
  <pre><code> private void btnRequest_Click(object sender, EventArgs e)  
      {
       var reader = new CardReader();
       reader.Start(CardReaded);
  }
  private void CardReaded(string cardnr){
  //txtSearchPurse.Text = _callback;
  </code></pre>
  
  <p>}</p>