473,788 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

background worker thread

From what im reading about backgroundworke r thread
it seems it can only have 1 thread at a time

is this correct
tks
Jan 16 '08 #1
8 10948
Analizer1 wrote:
From what im reading about backgroundworke r thread
it seems it can only have 1 thread at a time

is this correct
No.

What's more to say? You can have as many as the system reasonably allows. If
there's something else you're confused about, do ask.

--
J.
Jan 16 '08 #2
Jeroen Mostert wrote:
Analizer1 wrote:
>From what im reading about backgroundworke r thread
it seems it can only have 1 thread at a time

is this correct

No.

What's more to say? You can have as many as the system reasonably
allows. If there's something else you're confused about, do ask.
Of course, spacing is vital here. Do you mean a "background worker thread",
or "the thread used for a BackgroundWorke r instance"?

Every BackgroundWorke r instance is backed by only one thread, but you can
have multiple BackgroundWorke rs without any problem.

--
J.
Jan 16 '08 #3
public ThreadWorker: BackgroundWorke r

im using the above BackgroundWorke r

small sample from the threadManager class

for (int x=0:x<this.aWor kers.GetLength( 0);x++)
{
if (aWorkers[x].IsBusy=false)
{
int iJobNum = SombojectGetJob Num()
if (iJobNum>0)
{
aWorkers[x].RunWorkerAsync (iJobNum)
}
}
//as it assigns more jobs i get -This BackgroundWorke r is
currently busy and cannot run multiple tasks concurrently.
//it assign's a job , next one is complete or not busy and
assigns a new job
// It also seems to be assigning jobs to a busy thread

}
"Jeroen Mostert" <jm******@xs4al l.nlwrote in message
news:47******** *************** @news.xs4all.nl ...
Jeroen Mostert wrote:
>Analizer1 wrote:
>>From what im reading about backgroundworke r thread
it seems it can only have 1 thread at a time

is this correct

No.

What's more to say? You can have as many as the system reasonably allows.
If there's something else you're confused about, do ask.
Of course, spacing is vital here. Do you mean a "background worker
thread", or "the thread used for a BackgroundWorke r instance"?

Every BackgroundWorke r instance is backed by only one thread, but you can
have multiple BackgroundWorke rs without any problem.

--
J.

Jan 17 '08 #4
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <ve***********@ yahoo.com>
wrote:
[...]
//as it assigns more jobs i get -This BackgroundWorke r is
currently busy and cannot run multiple tasks concurrently.
As the error explains, a given BackgroundWorke r can only be running a
single background task at a time. As Jeroen points out, you can create as
many BackgroundWorke r instances as you like.

There will always be a limit as to the maximum number of threads you can
have running at any given time. So even creating a new BackgroundWorke r
for each task you want to start, eventually you'll exhaust the thread pool
and new BackgroundWorke r instances will have to wait for
previously-started ones to complete before they can themselves start. But
that's actually a good thing.

Also, if your background task is CPU-bound, you don't really want to start
a whole bunch of them all at once anyway. For CPU-bound stuff, it's
counter-productive to have more of them running than you have CPU cores,
at least from a through-put point of view.

Pete
Jan 17 '08 #5
i have only created 5 backbgroundwork er threads
I ran 100 jobs and 3 crashed with the previous error i posted..so im just
trying to track down the cause.

The threads actually call a couple of stored procs sql server 2005 sp2 and
update rows with new status Codes

tks

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <ve***********@ yahoo.com>
wrote:
>[...]
//as it assigns more jobs i get -This BackgroundWorke r is
currently busy and cannot run multiple tasks concurrently.

As the error explains, a given BackgroundWorke r can only be running a
single background task at a time. As Jeroen points out, you can create as
many BackgroundWorke r instances as you like.

There will always be a limit as to the maximum number of threads you can
have running at any given time. So even creating a new BackgroundWorke r
for each task you want to start, eventually you'll exhaust the thread pool
and new BackgroundWorke r instances will have to wait for
previously-started ones to complete before they can themselves start. But
that's actually a good thing.

Also, if your background task is CPU-bound, you don't really want to start
a whole bunch of them all at once anyway. For CPU-bound stuff, it's
counter-productive to have more of them running than you have CPU cores,
at least from a through-put point of view.

Pete

Jan 17 '08 #6
I got it working Right....Thank you for your help
in the ThreadCompleted Event
i had a Call To StartNew Jobs...instead of Enableing The Timer Event

thanks again

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <ve***********@ yahoo.com>
wrote:
>[...]
//as it assigns more jobs i get -This BackgroundWorke r is
currently busy and cannot run multiple tasks concurrently.

As the error explains, a given BackgroundWorke r can only be running a
single background task at a time. As Jeroen points out, you can create as
many BackgroundWorke r instances as you like.

There will always be a limit as to the maximum number of threads you can
have running at any given time. So even creating a new BackgroundWorke r
for each task you want to start, eventually you'll exhaust the thread pool
and new BackgroundWorke r instances will have to wait for
previously-started ones to complete before they can themselves start. But
that's actually a good thing.

Also, if your background task is CPU-bound, you don't really want to start
a whole bunch of them all at once anyway. For CPU-bound stuff, it's
counter-productive to have more of them running than you have CPU cores,
at least from a through-put point of view.

Pete

Jan 17 '08 #7
On Wed, 16 Jan 2008 16:53:19 -0800, Analizer1 <ve***********@ yahoo.com>
wrote:
i have only created 5 backbgroundwork er threads
Did you create threads? Or instances of the BackgroundWorke r class?

The two are not synonymous.
I ran 100 jobs and 3 crashed with the previous error i posted..so im just
trying to track down the cause.
The issue is as I described. If you get that error, it's because you're
trying to start a new task on a BackgroundWorke r that hasn't finished its
previous task.

The way to fix it is to not do that.

Pete

Jan 17 '08 #8
thanks for your help. peter

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Wed, 16 Jan 2008 16:53:19 -0800, Analizer1 <ve***********@ yahoo.com>
wrote:
>i have only created 5 backbgroundwork er threads

Did you create threads? Or instances of the BackgroundWorke r class?

The two are not synonymous.
>I ran 100 jobs and 3 crashed with the previous error i posted..so im just
trying to track down the cause.

The issue is as I described. If you get that error, it's because you're
trying to start a new task on a BackgroundWorke r that hasn't finished its
previous task.

The way to fix it is to not do that.

Pete

Jan 17 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
8563
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
1
1787
by: bilosta | last post by:
I need help with background worker and form I have a class (form1) that works with database. I need this: -Show form2 while form1 is geting data from database -When form1 is done, close form2, proced working form1 I try these things with thread but a can not do it I try it with background worker, but I dont know how:(
33
2007
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do that on an extra thread but I think it is a bad idea to spawn a new thread everytime a log-message is written and let it die once the message was written. But how do I keep a thread alive and trigger the log-messages and pass the string to that...
7
10070
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works great, at least on my system. The reason I am doing this is some customers are pulling from VPN connections which are slow. This allows the list of rows in the data grid to appear a little quicker while the list which are not used as soon load in...
6
5964
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. I'm wondering what would be the best way to do this , do I wait in a do...while loop for each to finish and then start another ? thanks Sunit
8
5371
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
13
10234
by: deciacco | last post by:
How can I have access to the items collection of a listview control on my form from a background thread? I know I need delegates to update the listview control and I have those calls in the foreach loop, but I'm not sure how to access the items collection. foreach (ListViewItem li in this.listview1.Items) { Invoke(new deleg(updatectrl), new object { param });
4
4314
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in a shared class. This other procedure has local variables but also refrences class level variables. I'm wondering if this might cause the DoWork routine to have to reach out to the primary thread, thus greatly slowing down the routine. How can...
7
3020
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do this: for (int i = 0; i < inputNum; i++) { string param = i.ToString();
2
5799
by: thoffman | last post by:
Hello again everyone! I have an issue that I can't seem to find a straight answer for anywhere... I have a For loop that sends a file name to a background worker that contains some long running code and I can't find a way for the parent thread to wait for the background worker to finish... Here is the example code: For i = 0 to 4 BacgroundWorker1.RunWorkerAsync(fileName(i)) Next Private Sub BackgroundWorker1(ByVal sender As...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.