How to know if thread is still running

  • Thread starter Thread starter DaWoE
  • Start date Start date
D

DaWoE

Hi all,

I have create an method that takes a while to process so my website
times out.

I used a thread to make sure the page doesn't times out.

The methode that i use to the processing is another the class than my
webform.

Public Class MyClass
Public Sub ProcessWork()
'this code takes at least 10 minutes to run
End Sub
End Class

This is my code when the user clicks a button

Dim obj as New MyClass
Dim objThread As New Thread(AddressOf MyClass.ProcessWork)

objThread.Start()


This code in process works executes fine now, but i want to make the
user aware that it is already running. How can I know if the thread is
still running ?
 
Assuming you've kept the objThread reference around you can always
check the IsAlive property.

HTH,
 
Scott said:
Assuming you've kept the objThread reference around you can always
check the IsAlive property.

HTH,

Where do you recommend that i keep it ? Session ?
 
It depends on how the long running process is used. If there can be
only one no matter how many users you have, then you could keep it
around in a shared or static (c#) reference.
 
Do you have an example of this ?

--
DaWoE

Scott said:
It depends on how the long running process is used. If there can be
only one no matter how many users you have, then you could keep it
around in a shared or static (c#) reference.
 
DaWoE:

If you have a class with a static member, like:

class Foo
{
public static int Bar;
}

Then you can reach the property from anywhere in the web application
by saying

int x = Foo.Bar;

In VB, the keyword is Shared, not static, and you can do this with any
type, not just an int. Be careful when you have multiple threads
reading and writing a static, because they have to share the instance.
 
Back
Top