.NET Framework Developer Center >
.NET Development Forums
>
.NET Base Class Library
>
Background worker thread for scanning file
Background worker thread for scanning file
- Hi
I have a WPF application with a menu option to kick off file scanning for certain keywords when the file is being written to the USB drive. I have the filter driver in place. I need to kick off a background thread that would wait infinitely for messages from the filter driver and according call the scan function. I used
AVworker = new BackgroundWorker();
AVworker.DoWork += AVworker_Dowork;
Within the AVworker_DoWork() function, I need to wait indefinitely for messages from the filter and process them. I need this thread to exit when the application is killed.
How do I do the wait in the background?
I tried an alternative method. When the menu option was invoked, I called unmanaged scan() function(part of a .dll) which in turn invoked a thread which did the waiting using WaitForMultipleObjects(). However, in this case, the application became unresponsive because of the wait. Hence I want to do the same in the background without using a while (1) kind of loop.
Answers
- Instead of using a BackgroundWorker, this is one case where I recommend actually spawning your own (background) thread. Just make sure to set IsBackground to true so it doesn't keep the application from shutting down.
The thread can just wait as needed, using WaitForSingleObject() or WaitForMultipleObjects(), etc.
Reed Copsey, Jr. - http://reedcopsey.com- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorMonday, November 16, 2009 1:55 PM
All Replies
- Instead of using a BackgroundWorker, this is one case where I recommend actually spawning your own (background) thread. Just make sure to set IsBackground to true so it doesn't keep the application from shutting down.
The thread can just wait as needed, using WaitForSingleObject() or WaitForMultipleObjects(), etc.
Reed Copsey, Jr. - http://reedcopsey.com- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorMonday, November 16, 2009 1:55 PM
- Hello PhoebeC
How are you? I think that Reed provided a good suggestion. Could you please check it out and let us know your feedback? If you have any other questions or concerns, please feel free to post here.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


