Threading Question

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?
 
F

Fergus Cooney

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
 
A

Armin Zingler

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_.
 
C

Christine Nguyen

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....
 
F

Fergus Cooney

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
 
H

Herfried K. Wagner [MVP]

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.
 
F

Fergus Cooney

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
 
C

Christine Nguyen

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top