473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 1663
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
1
by: ditnooitlezen | last post by:
Hi, the (.NET 2.0) backgroundworker object has a DoWork method that operates in a background thread. When the DoWork method is finished the RunWorkerCompleted event is raised in the parent...
9
by: =?Utf-8?B?VE9NX1Bhc2FkZW5h?= | last post by:
Hello, In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load function. In that thread I'm attempting to connect to a SQL server using this connection string "Initial...
7
by: =?Utf-8?B?SGVucnk5OQ==?= | last post by:
What happens here? The backgroundworker (bgw) unzips RTF-Helpfiles (up to 1 MB in size). The ProgressChanged-Event gets the unzipped files (to display them in a RichtTextBox) It follows the...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
4
by: Sin Jeong-hun | last post by:
This is what I've always been wondered. Suppose I've created a class named Agent, and the Agent does some lengthy job. Of course I don't want to block the main window, so the Agent does the job in...
3
by: Coaster | last post by:
I want to create a "thread manager" class to manage an array of backgroundworkers. I'd like this thread manager class to live in a class library and I wasn't sure if it was possible to make the...
2
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have introduced a component to my solution that is throwing an exception about needing to be run in single threaded apartment mode. This component is created in an async call by a...
1
by: schnandr | last post by:
Hi, I have a user control which contains ListView. I copy all ListViewItems into a separate List<ListViewItemcalled unfilteredItems. I am using a BackgroundWorker to filter the ListView. When...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.