Thread.Start and threadstate unstarted

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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?
 
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.
 
Cedric said:
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
 
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.
 
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.
 
Back
Top