I have a stylistic question about the choice of background thread implementation I should use on a windows form app. Currently I have a BackgroundWorker
on a form that has an infinite (while(true))
loop. In this loop I use WaitHandle.WaitAny
to keep the thread snoozing until something of interest happens. One of the event handles I wait on is a "StopThread
" event so that I can break out of the loop. This event is signaled when from my overridden Form.Dispose()
.
I read somewhere that BackgroundWorker
is really intended for operations that you don't want to tie up the UI with and have an finite end - like downloading a file, or processing a sequence of items. In this case the "end" is unknown and only when the window is closed. Therefore would it be more appropriate for me to use a background Thread instead of BackgroundWorker
for this purpose?
Some of my thoughts...