473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to restart "Stopped" thread?

I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett

Nov 21 '05 #1
22 37662
Typically you would start a new thread. thread.abort will not allow that
thread ever to start again. I think if you do a thread.suspend you can
restart it.

Chris

"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett

Nov 21 '05 #2
"Brett" <no@spam.com> schrieb:
I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.

How can this thread restart?
If a thread's state is 'Stopped', the thread is either responding to an
'Abort' request or it is terminated. Create a new thread instead of dealing
with the stopped thread.
Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?


Yes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
I see. Right now I do this to create the new thread initially when Form1
loads:

Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))

The occurs outside of any sub. I have a button to do t.start() initially.
Once the thread is "stopped" and cannot be restarted, you're saying I need
to create another/new thread. How can I do that in the sub() of this
button? I can't declare Public because I'll get:

Public is not valid on local variable declaration

I need the new thread to be public so sub()s in Form1 can access it.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:u5**************@tk2msftngp13.phx.gbl...
Typically you would start a new thread. thread.abort will not allow that
thread ever to start again. I think if you do a thread.suspend you can
restart it.

Chris

"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I have a second thread, t2, that errors out and will stop. It's status is
then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated;
it can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett


Nov 21 '05 #4
I'm a little confused. You need any procedure in Form1 to be able to access
a thread. Make the reference to the thread public in form1 then. I think
this is what you need to do.
Note: This code isn't perfect, just trying to show the idea. There are
examples in MSDN you can look at.
Public Class Form1

Public t As System.Threading.Thread

Sub StartThread
t = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))
t.start
End Sub
sub SomeSubInForm1
t.abort()
Me.StartThread()
end sub
End Class

Public Class Class1
Public Static Sub callSomeSub
End Class
End Class
"Brett" <no@spam.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
I see. Right now I do this to create the new thread initially when Form1
loads:

Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))

The occurs outside of any sub. I have a button to do t.start() initially.
Once the thread is "stopped" and cannot be restarted, you're saying I need
to create another/new thread. How can I do that in the sub() of this
button? I can't declare Public because I'll get:

Public is not valid on local variable declaration

I need the new thread to be public so sub()s in Form1 can access it.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:u5**************@tk2msftngp13.phx.gbl...
Typically you would start a new thread. thread.abort will not allow that
thread ever to start again. I think if you do a thread.suspend you can
restart it.

Chris

"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I have a second thread, t2, that errors out and will stop. It's status
is then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated;
it can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett



Nov 21 '05 #5
I see. I was trying to declare t twice when all I need to do was give it a
value.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub**************@TK2MSFTNGP10.phx.gbl...
I'm a little confused. You need any procedure in Form1 to be able to
access a thread. Make the reference to the thread public in form1 then.
I think this is what you need to do.
Note: This code isn't perfect, just trying to show the idea. There are
examples in MSDN you can look at.
Public Class Form1

Public t As System.Threading.Thread

Sub StartThread
t = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))
t.start
End Sub
sub SomeSubInForm1
t.abort()
Me.StartThread()
end sub
End Class

Public Class Class1
Public Static Sub callSomeSub
End Class
End Class
"Brett" <no@spam.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
I see. Right now I do this to create the new thread initially when Form1
loads:

Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))

The occurs outside of any sub. I have a button to do t.start()
initially. Once the thread is "stopped" and cannot be restarted, you're
saying I need to create another/new thread. How can I do that in the
sub() of this button? I can't declare Public because I'll get:

Public is not valid on local variable declaration

I need the new thread to be public so sub()s in Form1 can access it.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:u5**************@tk2msftngp13.phx.gbl...
Typically you would start a new thread. thread.abort will not allow
that thread ever to start again. I think if you do a thread.suspend you
can restart it.

Chris

"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I have a second thread, t2, that errors out and will stop. It's status
is then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated;
it can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett




Nov 21 '05 #6
If the thread2 is suspended, how can I kill it? Say my application is
shutting down, I can do t2.abort() but that will throw an error, which I'll
need to catch. I can do nothing and just shut the app down. However, the
thread doesn't remove itself from memory.

I have to do a
t2.resume()
t2.sleep(x)
t2.abort()

for it to remove from memory.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:ub**************@TK2MSFTNGP10.phx.gbl...
I'm a little confused. You need any procedure in Form1 to be able to
access a thread. Make the reference to the thread public in form1 then.
I think this is what you need to do.
Note: This code isn't perfect, just trying to show the idea. There are
examples in MSDN you can look at.
Public Class Form1

Public t As System.Threading.Thread

Sub StartThread
t = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))
t.start
End Sub
sub SomeSubInForm1
t.abort()
Me.StartThread()
end sub
End Class

Public Class Class1
Public Static Sub callSomeSub
End Class
End Class
"Brett" <no@spam.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
I see. Right now I do this to create the new thread initially when Form1
loads:

Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))

The occurs outside of any sub. I have a button to do t.start()
initially. Once the thread is "stopped" and cannot be restarted, you're
saying I need to create another/new thread. How can I do that in the
sub() of this button? I can't declare Public because I'll get:

Public is not valid on local variable declaration

I need the new thread to be public so sub()s in Form1 can access it.

Thanks,
Brett

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:u5**************@tk2msftngp13.phx.gbl...
Typically you would start a new thread. thread.abort will not allow
that thread ever to start again. I think if you do a thread.suspend you
can restart it.

Chris

"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I have a second thread, t2, that errors out and will stop. It's status
is then "Stopped". I try to start t2 from thread 1, t1, by checking

If t2.threadstate = "Stopped" Then
t2.start()

However, this throws and error:

System.Threading.ThreadStateException: Thread is running or terminated;
it can not restart.

How can this thread restart?

Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?

Thanks,
Brett




Nov 21 '05 #7
"Brett" <no@spam.net> schrieb:
If the thread2 is suspended, how can I kill it? Say my application is
shutting down, I can do t2.abort() but that will throw an error, which
I'll need to catch. I can do nothing and just shut the app down.
However, the thread doesn't remove itself from memory.


Set the thread's 'IsBackground' property to 'True'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...
"Brett" <no@spam.net> schrieb:
If the thread2 is suspended, how can I kill it? Say my application is
shutting down, I can do t2.abort() but that will throw an error, which
I'll need to catch. I can do nothing and just shut the app down.
However, the thread doesn't remove itself from memory.


Set the thread's 'IsBackground' property to 'True'.

Perfect. Thanks.

Brett
Nov 21 '05 #9

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OP**************@TK2MSFTNGP10.phx.gbl...
"Brett" <no@spam.net> schrieb:
If the thread2 is suspended, how can I kill it? Say my application is
shutting down, I can do t2.abort() but that will throw an error, which
I'll need to catch. I can do nothing and just shut the app down.
However, the thread doesn't remove itself from memory.


Set the thread's 'IsBackground' property to 'True'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

When I put a thread to sleep, t.sleep(x), how can I find out the current
value of x? Say x is initially 60000 (one minute). I do t.sleep(x). After
some number of seconds but less than one minute, I'd like to know the x
sleep value (for lack of better words). Perhaps it is at 20 seconds or 36
seconds. Even better, I'd like to display a real time count up/down of the
seconds in a textbox. Any suggestions?

Thanks,
Brett
Nov 21 '05 #10
"Brett" <no@spam.net> schrieb:
When I put a thread to sleep, t.sleep(x), how can I find out the current
value of x? Say x is initially 60000 (one minute). I do t.sleep(x).
After some number of seconds but less than one minute, I'd like to know
the x sleep value (for lack of better words). Perhaps it is at 20 seconds
or 36 seconds. Even better, I'd like to display a real time count up/down
of the seconds in a textbox.


Add a 'System.Windows.Forms.Timer' to your form, place the code to update
the time in its 'Tick' event handler and use
'Control.Invoke'/'Control.BeginInvoke' to enable it from within the 2nd
thread directly before calling 'Sleep' on the thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #11

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
"Brett" <no@spam.net> schrieb:
When I put a thread to sleep, t.sleep(x), how can I find out the current
value of x? Say x is initially 60000 (one minute). I do t.sleep(x).
After some number of seconds but less than one minute, I'd like to know
the x sleep value (for lack of better words). Perhaps it is at 20
seconds or 36 seconds. Even better, I'd like to display a real time
count up/down of the seconds in a textbox.


Add a 'System.Windows.Forms.Timer' to your form, place the code to update
the time in its 'Tick' event handler and use
'Control.Invoke'/'Control.BeginInvoke' to enable it from within the 2nd
thread directly before calling 'Sleep' on the thread.


I do have a timer on Form1 to poll t2.threadstate from Form1. I then
display this value every second as a string in a label. Say the timer is
named tmr1. Are you saying to do tmr1.Invoke/tmr1.BeginInvoke? The timer
doesn't have those methods.

I think if you knew I had a timer, you are saying to do this:

Public Class Class1

Form1.DoSleepCount = 1
Thread.CurrentThread.sleep(x)
Form1.DoSleepCount = 0
Form1.Label2.Text = ""

Public Class Form1

Public count as Integer = 1
Public Shared DoSleepCount as Integer = 0

Public Sub SleepCount()
count += 1
Form1.Label2.Text = count.ToString
End Sub

Private Sub tmr1
-- do something here--
If DoSleepCount = 1 Then
SleepCount()
End If
End Sub

That seem correct?

Thanks,
Brett
Nov 21 '05 #12
"Brett" <no@spam.net> schrieb:
I do have a timer on Form1 to poll t2.threadstate from Form1. I then
display this value every second as a string in a label. Say the timer is
named tmr1. Are you saying to do tmr1.Invoke/tmr1.BeginInvoke? The
timer doesn't have those methods.


You are right, my bad. 'Timer' does not have these methods because it's not
a control. So, instead, add methods or a property to your form that will
enable/disable the timer, and call these methods or set this property by
using the form's 'Invoke'/'BeginInvoke' method. Instance members of
'System.Windows.Forms.Timer' are not safe for multithreading, so you cannot
access them directly from within an other thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #13

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Brett" <no@spam.net> schrieb:
I do have a timer on Form1 to poll t2.threadstate from Form1. I then
display this value every second as a string in a label. Say the timer is
named tmr1. Are you saying to do tmr1.Invoke/tmr1.BeginInvoke? The
timer doesn't have those methods.


You are right, my bad. 'Timer' does not have these methods because it's
not a control. So, instead, add methods or a property to your form that
will enable/disable the timer, and call these methods or set this property
by using the form's 'Invoke'/'BeginInvoke' method. Instance members of
'System.Windows.Forms.Timer' are not safe for multithreading, so you
cannot access them directly from within an other thread.


Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text object.
That should be safe correct?

Thanks again,
Brett
Nov 21 '05 #14
Brett,
Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text
object. That should be safe correct? Form1.Label2 is a control, it's property .Text cannot be accessed safely
from another thread.

Hope this helps
Jay

"Brett" <no@spam.com> wrote in message
news:eT**************@tk2msftngp13.phx.gbl...
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Brett" <no@spam.net> schrieb:
I do have a timer on Form1 to poll t2.threadstate from Form1. I then
display this value every second as a string in a label. Say the timer
is named tmr1. Are you saying to do tmr1.Invoke/tmr1.BeginInvoke? The
timer doesn't have those methods.


You are right, my bad. 'Timer' does not have these methods because it's
not a control. So, instead, add methods or a property to your form that
will enable/disable the timer, and call these methods or set this
property by using the form's 'Invoke'/'BeginInvoke' method. Instance
members of 'System.Windows.Forms.Timer' are not safe for multithreading,
so you cannot access them directly from within an other thread.


Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text
object. That should be safe correct?

Thanks again,
Brett

Nov 21 '05 #15

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Brett,
Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text
object. That should be safe correct?

Form1.Label2 is a control, it's property .Text cannot be accessed safely
from another thread.

Hope this helps
Jay


Why is that?

Thanks,
Brett
Nov 21 '05 #16
"Brett" <no@spam.com> schrieb:
Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text
object. That should be safe correct?


Form1.Label2 is a control, it's property .Text cannot be accessed safely
from another thread.


Why is that?


That's because instance members of Windows Forms controls are not safe for
multithreading (... or do you want to know the reasons for that?). You can
use 'Control.Invoke'/'Control.BeginInvoke' to access the label's 'Text'
property to overcome this limitation.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #17
Brett,
It uses Win32 controls underneath, Win32 controls are not designed to be
thread safe.

Most of the time you do not need your objects (both your the classes you
define & Win32 controls) to be thread as, as only one thread will access the
object at a time. Only in the case, such as this, where you want to update
one object from another thread do you need to worry about thread safety. The
designers of Win32 & .NET decided that its rare to access a control from
another thread, so they did not design safety in. If they did design thread
safety in, then each method would effectively need a SyncLock statement in
it, all this SyncLock statements would have a negative impact on
non-multithreaded applications...

Also think about in your case you only want to update Text, if Label were
thread safe *ALL* properties would need to be thread safe. Do you want a
performance hit on all methods simply to update Text? Would it not be better
to write special code (Control.BeginInvoke) to update just the Text
property?

Hope this helps
Jay

"Brett" <no@spam.com> wrote in message
news:O0****************@TK2MSFTNGP14.phx.gbl...

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
Brett,
Well, using the code I posted, the timer won't actually be accessed from
another thread. Just Form1's DoSleepCount var and Form1.Label2.Text
object. That should be safe correct?

Form1.Label2 is a control, it's property .Text cannot be accessed safely
from another thread.

Hope this helps
Jay


Why is that?

Thanks,
Brett

Nov 21 '05 #18
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
designers of Win32 & .NET decided that its rare to access a control from
another thread, so they did not design safety in. If they did design
thread safety in, then each method would effectively need a SyncLock
statement in it, all this SyncLock statements would have a negative impact
on non-multithreaded applications...


[For the records:]

Not only Windows Forms made this decision, you will rarely find a
multithreading-safe GUI package:

Multithreaded toolkits: A failed dream?
<URL:http://weblogs.java.net/blog/kgh/archive/2004/10/multithreaded_t.html>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #19

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ow*************@TK2MSFTNGP10.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb:
designers of Win32 & .NET decided that its rare to access a control from
another thread, so they did not design safety in. If they did design
thread safety in, then each method would effectively need a SyncLock
statement in it, all this SyncLock statements would have a negative
impact on non-multithreaded applications...


[For the records:]

Not only Windows Forms made this decision, you will rarely find a
multithreading-safe GUI package:

Multithreaded toolkits: A failed dream?
<URL:http://weblogs.java.net/blog/kgh/archive/2004/10/multithreaded_t.html>


What if I do this:

Form1.DoSleepCount = 1
Thread.CurrentThread.sleep(x)
Form1.DoSleepCount = 0

Where
Form1.Label2.Text = ""

is inside of DoSleepCount. Is that thread safe?

I suppose its more that I don't understand the concept of
Label2.invoke/begininvoke. Can you show some sample code?

Thanks,
Brett
Nov 21 '05 #20
"Brett" <no@spam.com> schrieb> What if I do this:
Form1.DoSleepCount = 1
Thread.CurrentThread.sleep(x)
Form1.DoSleepCount = 0

Where
Form1.Label2.Text = ""

is inside of DoSleepCount. Is that thread safe?
What's 'DoSleepCount'? According to a sample you posted previously it's a
variable. So, how would you set the label's text "inside" 'DoSleepCount'?
I suppose its more that I don't understand the concept of
Label2.invoke/begininvoke. Can you show some sample code?


A sample that uses this technique can be found here:

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/#FileSystemEnumerator>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #21

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Brett" <no@spam.com> schrieb> What if I do this:
Form1.DoSleepCount = 1
Thread.CurrentThread.sleep(x)
Form1.DoSleepCount = 0

Where
Form1.Label2.Text = ""

is inside of DoSleepCount. Is that thread safe?
What's 'DoSleepCount'? According to a sample you posted previously it's a
variable. So, how would you set the label's text "inside" 'DoSleepCount'?


Sorry, I meant the sub() named SleepCount():

Public Sub SleepCount()
count += 1
Form1.Label2.Text = count.ToString
Form1.Label2.Text = ""
End Sub
I suppose its more that I don't understand the concept of
Label2.invoke/begininvoke. Can you show some sample code?
A sample that uses this technique can be found here:

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/#FileSystemEnumerator>


Sorry, my German isn't that great. I tried a Google translation but it
failed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #22
"Brett" <no@spam.com> schrieb:
Form1.DoSleepCount = 1
Thread.CurrentThread.sleep(x)
Form1.DoSleepCount = 0

Where
Form1.Label2.Text = ""

is inside of DoSleepCount. Is that thread safe?


What's 'DoSleepCount'? According to a sample you posted previously it's
a variable. So, how would you set the label's text "inside"
'DoSleepCount'?


Sorry, I meant the sub() named SleepCount():

Public Sub SleepCount()
count += 1
Form1.Label2.Text = count.ToString
Form1.Label2.Text = ""
End Sub


If you call 'SleepCount' from within the procedure that is executing in its
separate thread, it will be executed in this thread too. Consequently you
will have to use 'Control.Invoke'/'Control.BeginInvoke' in this situation
too.
I suppose its more that I don't understand the concept of
Label2.invoke/begininvoke. Can you show some sample code?


A sample that uses this technique can be found here:

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/#FileSystemEnumerator>


Sorry, my German isn't that great. I tried a Google translation but it
failed.


Sorry, wrong link. I wanted to refer to the downloadable sample:

FileSystemEnumerator
<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/FileSystemEnumerator.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Ross Bennett | last post by:
Ahoy, Folks! I've been looking all over for this, but I just can't seem to shake any documentation out of the MSDN or from Google. I've reviewed every .NET article on developing Windows...
0
by: Diffident | last post by:
Hello All, I am trying to do a "build" of all files of my web app on my local machine. I know that there is an "aspnet_wp.exe" running forever on my machine and to my knowledge each web app is...
6
by: alessandro | last post by:
Hi all, This is my framework for create TCP server listening forever on a port and supporting threads: import SocketServer port = 2222 ip = "192.168.0.4"
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.