I want to do a simple thing.
I have a secondary thread listening to a usb reader, when the reader “reads” something, the thread fires an event. And that event starts a timer, but the timer does not work, I’m sure it is because about the threads.
Also, the timer must change some images in the form so this must be done in the main thread.
I hope I’m clear.
private void listenReader()
{
while (whileState)
{
if (readsSomething)
{
evt.OnSomeEvent();
break;
}
}
}
private void eventStartsThisMethot(){
//do a lot of things and start the timer
}
private void counter(){
pictureBox.Image = Resources._5;
//the timer ticks this methot
}
So, listen reader need to be on separate thread for obvious reasons, but the second method must be done from the main thread, so I use an event, but if you have another idea.
Thanks
Since you added the [picturebox] tag, we can assume this is Windows Forms (Winforms). The event handler for your reader thread will execute on the reader thread and you need to execute code (in response to the event) on the UI thread.
You can use your Form’s
BeginInvokemethod to execute arbitrary code on the UI thread