Click to See Complete Forum and Search --> : How To Listen to Thread Events


urugedoc101122
September 3rd, 2009, 06:50 AM
Hi,

I've been assigned a project to be implemented in C#. Here's a little overview on the system:

The application will have 2 threads:
1. Main thread - handles the main application - GUI, file handling etc...
2. Monitor Thread - frequently checks/polls on the status of a USB port.

The premise is a USB thumb drive needs to be connected ALWAYS in order for the main application to run. If the thumb drive was removed, the main application will stop any processing, lock itself and show a prompt saying to re-insert the USB drive.

My idea is that the monitor thread will have one property boolean IsUSBPresent. whenever this changes value, it will send an event or signal to the main thread. The main thread will then perform the appropriate action in handling the event.

My problem now is I dont have any idea how to implement it. Is there a way for the main thread to "listen" to that property - something like an OnIsUSBPresentChanged event...

I've been browsing and complex things come up like delegates, custom events etc...
I'm hoping someone can point me to an article or a tutorial

Any help would be appreciated. Thanks a bunch!. ^_^

monalin
September 3rd, 2009, 09:36 AM
Hi, i don't have any experience using USB devices so i'm sure someone else can give you some better advice but I managed to find this article with some 3rd party code you can use to connect to a USB device.

http://blogs.msdn.com/coding4fun/archive/2006/10/31/912422.aspx

Here is the API, it appears there is an event StatusChanged which you can attach too and maybe that will fire it for you.

http://blogs.msdn.com/blogfiles/coding4fun/some_assembly_required/isthatyou/coreL.gif

urugedoc101122
September 5th, 2009, 05:37 AM
Thanks Monalin :D looks good so far. I'll just have to test it wth the some code.