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
>>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.
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <vettes_n_jets@ 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.
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" <NpOeStPeAdM@nn owslpianmk.comw rote in message
news:op.t41suzf 48jd0ej@petes-computer.local. ..
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <vettes_n_jets@ 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
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" <NpOeStPeAdM@nn owslpianmk.comw rote in message
news:op.t41suzf 48jd0ej@petes-computer.local. ..
On Wed, 16 Jan 2008 16:08:29 -0800, Analizer1 <vettes_n_jets@ 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
On Wed, 16 Jan 2008 16:53:19 -0800, Analizer1 <vettes_n_jets@ 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.
"Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
news:op.t41u4ai 18jd0ej@petes-computer.local. ..
On Wed, 16 Jan 2008 16:53:19 -0800, Analizer1 <vettes_n_jets@ 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
>
Comment