468,140 Members | 1,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

BackgroundWorker / Thread question

I have a question.

One day i have been working with threads. Thread had 'while' loop that
checked locked value telling the thread when application was closing
( in Dispose method i set locked object's value to 'true'). If i
didn't have the locked object the thread was present in taskmanager
even when application has been already gone.

My question is:

Having while loop in background worker i don't have to care about
closing conditions.
Even if i have while(true) and i close the application, the thread is
closed. Don't know why and when. Completed event is not raised - but
it normally it is during an exception for example.

Why is it so?

Thanks and regards
PK

Sep 16 '07 #1
3 1453
Thank you so much for the response.
One question remains... Is there anything that can't be done with
backgroundworker threads? Why to use regular thread instead of BW?

Sep 16 '07 #2
The System.Threading.Thread.IsBackground is just what i was looking
for. Thank you.

Sep 16 '07 #3
Piotrekk wrote:
Thank you so much for the response.
One question remains... Is there anything that can't be done with
backgroundworker threads? Why to use regular thread instead of BW?
BackgroundWorker uses the thread pool. The pool starts with a small
number of threads, and you get more as you start consuming them. The
thread pool is very useful for situations in which you repeatedly start
background tasks and don't want the overhead of creating new threads
over and over.

If you have a single task that you expect to take a long time, you might
as well just create a new thread yourself. It's not a good idea to set
IsBackground on a thread pool thread anyway, and a regular Thread
instance will be a foreground thread by default.

Pete
Sep 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ditnooitlezen | last post: by
9 posts views Thread by =?Utf-8?B?VE9NX1Bhc2FkZW5h?= | last post: by
7 posts views Thread by =?Utf-8?B?SGVucnk5OQ==?= | last post: by
2 posts views Thread by =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.