EDIT from @DanPuzey's comments. StartMonitoring
already monitors on another thread. The key is that the CardArrived
event is not being raised from the UI thread:
public PersonCredential()
{
InitializeComponent();
SCLib type = new SCLib();
type.StartMonitoring();
type.CardArrived += (string ATR) => {
// when card arrives, dispatch back to UI thread
Dispatcher.BeginInvoke(new Action(() => {
this.CardHolderName.Content = ATR;
}));
};
}
And if you are using .NET 4 or higher, use Task.Factory.StartNew()
instead of new Thread()
.