Home All Groups Group Topic Archive Search About

Thread.Start and threadstate unstarted

Author
19 May 2006 2:00 PM
Cedric
Hello, I have a code which start 1 thread do some work start an another
thread do again some work and then wait for previous started thread to join.

I see sometime that even I use thread.start my threadstate is still
"unstarted".

I saw on doc that when start is invoked that the os schedule the job but I
saw also that the threadstate is also defined on "Running".

So my question is :
Is there a way to refresh the threadstate or increasing the thread priority ?
I'm using VB.NET 2003

Thanks for help

Author
19 May 2006 2:53 PM
Dmytro Lapshyn [MVP]
Hi,

It is possible to increase thread priority, but it is quite uncommon to do
that for a background worker thread.

On the other hand, why would you worry about a thread being "unstarted"
right after calling Thread.Start if the thread eventually starts anyway?

Show quote
"Cedric" <Ced***@discussions.microsoft.com> wrote in message
news:B190865F-2CDD-4AAC-BBDD-C2262937576A@microsoft.com...
> Hello, I have a code which start 1 thread do some work start an another
> thread do again some work and then wait for previous started thread to
> join.
>
> I see sometime that even I use thread.start my threadstate is still
> "unstarted".
>
> I saw on doc that when start is invoked that the os schedule the job but I
> saw also that the threadstate is also defined on "Running".
>
> So my question is :
> Is there a way to refresh the threadstate or increasing the thread
> priority ?
> I'm using VB.NET 2003
>
> Thanks for help
Author
19 May 2006 3:13 PM
Cedric
I'm worry about a thread being "unstarted" because it's NOT right after
calling start.
It's may be something like 100 lines of code that main thread execute
between the start and the "reel" start.

If my main thread must wait for other thread to "start" and do their job,
threading is useless.

Anyway, why my threadstate is unstarted even if I already called start ? May
be there is something to specify in doc.

Best Regards.

Show quote
"Dmytro Lapshyn [MVP]" wrote:

> Hi,
>
> It is possible to increase thread priority, but it is quite uncommon to do
> that for a background worker thread.
>
> On the other hand, why would you worry about a thread being "unstarted"
> right after calling Thread.Start if the thread eventually starts anyway?
>
> "Cedric" <Ced***@discussions.microsoft.com> wrote in message
> news:B190865F-2CDD-4AAC-BBDD-C2262937576A@microsoft.com...
> > Hello, I have a code which start 1 thread do some work start an another
> > thread do again some work and then wait for previous started thread to
> > join.
> >
> > I see sometime that even I use thread.start my threadstate is still
> > "unstarted".
> >
> > I saw on doc that when start is invoked that the os schedule the job but I
> > saw also that the threadstate is also defined on "Running".
> >
> > So my question is :
> > Is there a way to refresh the threadstate or increasing the thread
> > priority ?
> > I'm using VB.NET 2003
> >
> > Thanks for help
>
>
Author
19 May 2006 4:00 PM
Goran Sliskovic
Show quote
"Cedric" <Ced***@discussions.microsoft.com> wrote in message
news:F181EED0-7038-4C21-B187-4FAFB53280A9@microsoft.com...
> I'm worry about a thread being "unstarted" because it's NOT right after
> calling start.
> It's may be something like 100 lines of code that main thread execute
> between the start and the "reel" start.
>
> If my main thread must wait for other thread to "start" and do their job,
> threading is useless.
>
> Anyway, why my threadstate is unstarted even if I already called start ?
May
> be there is something to specify in doc.
>
> Best Regards.
....

It is maybe a bit confusing to see that state, however it does not change
much. This probably happens because transition from "unstarted" to "started"
is done by some prolouge routing in C# framework (after OS started thread,
but before delegate method has been called). Whan you call Start(),
framework probably starts thread but OS schedules it for later execution. It
won't be executed until it's time slice has come. Time slices are about
10ms, which means you main thread will have that much time execute futher.

You don't have to wait for thread to start. Why would you do that? After you
called Start, it will be started. You spawn new thread and continue work on
main thread.

Goran
Author
19 May 2006 9:12 PM
Cedric
In fact, my main thread needs data collected (AD query and Registry Query)
to continue his job.

But anyway, I will add in my sub which is testing thread state, the fact
that my threads could be unstarted even if I call start earlier.

Show quote
"Goran Sliskovic" wrote:
>
> "Cedric" <Ced***@discussions.microsoft.com> wrote in message
> news:F181EED0-7038-4C21-B187-4FAFB53280A9@microsoft.com...
> > I'm worry about a thread being "unstarted" because it's NOT right after
> > calling start.
> > It's may be something like 100 lines of code that main thread execute
> > between the start and the "reel" start.
> >
> > If my main thread must wait for other thread to "start" and do their job,
> > threading is useless.
> >
> > Anyway, why my threadstate is unstarted even if I already called start ?
> May
> > be there is something to specify in doc.
> >
> > Best Regards.
> ....
>
> It is maybe a bit confusing to see that state, however it does not change
> much. This probably happens because transition from "unstarted" to "started"
> is done by some prolouge routing in C# framework (after OS started thread,
> but before delegate method has been called). Whan you call Start(),
> framework probably starts thread but OS schedules it for later execution. It
> won't be executed until it's time slice has come. Time slices are about
> 10ms, which means you main thread will have that much time execute futher.
>
> You don't have to wait for thread to start. Why would you do that? After you
> called Start, it will be started. You spawn new thread and continue work on
> main thread.
>
> Goran
>
>
>
Author
22 May 2006 9:27 AM
Dmytro Lapshyn [MVP]
BTW it is actually a bad idea to freeze the main thread by having it wait
for a background worker thread. It would make your application unresponsive.
Your main thread still has something to do anyway, say, repainting the
application's window or processing user input.

Hence, just wait for a callback from the worker thread indicating the
background task has completed and the results are available.

Show quote
"Cedric" <Ced***@discussions.microsoft.com> wrote in message
news:30DA4FE2-D8FB-487D-B250-7DC55C9A30B0@microsoft.com...
> In fact, my main thread needs data collected (AD query and Registry Query)
> to continue his job.
>
> But anyway, I will add in my sub which is testing thread state, the fact
> that my threads could be unstarted even if I call start earlier.
>
> "Goran Sliskovic" wrote:
>>
>> "Cedric" <Ced***@discussions.microsoft.com> wrote in message
>> news:F181EED0-7038-4C21-B187-4FAFB53280A9@microsoft.com...
>> > I'm worry about a thread being "unstarted" because it's NOT right after
>> > calling start.
>> > It's may be something like 100 lines of code that main thread execute
>> > between the start and the "reel" start.
>> >
>> > If my main thread must wait for other thread to "start" and do their
>> > job,
>> > threading is useless.
>> >
>> > Anyway, why my threadstate is unstarted even if I already called start
>> > ?
>> May
>> > be there is something to specify in doc.
>> >
>> > Best Regards.
>> ....
>>
>> It is maybe a bit confusing to see that state, however it does not change
>> much. This probably happens because transition from "unstarted" to
>> "started"
>> is done by some prolouge routing in C# framework (after OS started
>> thread,
>> but before delegate method has been called). Whan you call Start(),
>> framework probably starts thread but OS schedules it for later execution.
>> It
>> won't be executed until it's time slice has come. Time slices are about
>> 10ms, which means you main thread will have that much time execute
>> futher.
>>
>> You don't have to wait for thread to start. Why would you do that? After
>> you
>> called Start, it will be started. You spawn new thread and continue work
>> on
>> main thread.
>>
>> Goran
>>
>>
>>

AddThis Social Bookmark Button