Threading Question

  • Thread starter Thread starter IcedCrow
  • Start date Start date
I

IcedCrow

I have code:

Dim th as new threading.thread(addressof MyMethod)
th.start()
If th.threadstate = threadstate.running then
th.priority = threading.threadpriority.abovenormal
End If

My question is... wouldn't the thread always be running
and the if statement always fire off with setting the
priority?
 
Hi IcedCrow,

Assuming that the thread has had enough time to finish starting [as it
were ;-)], that nothing went wrong, and also that it doesn't immediately send
itself to sleep, then yes, th.threadstate should be threadstate.running.

Regards,
Fergus
 
IcedCrow said:
I have code:

Dim th as new threading.thread(addressof MyMethod)
th.start()
If th.threadstate = threadstate.running then
th.priority = threading.threadpriority.abovenormal
End If

My question is... wouldn't the thread always be running
and the if statement always fire off with setting the
priority?

You ask because it doesn't? ;-) The thread does not start immediatelly. The
OS takes it into account when scheduling all threads, and it is started when
it is it's turn. Til it is started, it's state is ThreadState.Unstarted.

I read in the docs that the state is not Started before the Start method is
called. Well, that's right, but it doesn't change to Started _immediatelly_.
 
theoretically, I think it's possible that the thread could finish running
before th.threadstate's value is actually tested, especially if the main
thread lost it's time slice right after th.start(). Also, I'm not sure if
chaning priorities has much effect on a thread that has already been
started, but that's just conjecture....
 
Hi Christine,

|| I'm not sure if changing priorities has much effect on a thread
|| that has already been started, but that's just conjecture....

It seems reasonable that you can. Task Manager allows this to be done on
the context menu of each process.

Regards,
Fergus
 
Hello,

Christine Nguyen said:
Also, I'm not sure if chaning priorities has much effect on a thread
that has already been started, but that's just conjecture....

Should work.
 
Hi IcedCrow,

I saw your query in the xml newsgroup and posted a message but it seems to
have joined the multitude in the void.

It was just to tell you that I've answered a query in this newsgroup about
namespaces. You might want to have a read.

Topic: using xml schema with xmlDOm in .net
Dated: 26th Sep, 2:03am
Sender: Yair Cohen

Regards,
Fergus
 
Thanks Fergus and Herfried.

Christine Nguyen said:
theoretically, I think it's possible that the thread could finish running
before th.threadstate's value is actually tested, especially if the main
thread lost it's time slice right after th.start(). Also, I'm not sure if
chaning priorities has much effect on a thread that has already been
started, but that's just conjecture....
 
Back
Top