How to know if thread is still running

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

Scott Allen

Assuming you've kept the objThread reference around you can always
check the IsAlive property.

HTH,
 
D

DaWoE

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

Scott Allen

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

DaWoE

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

Scott Allen

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.
 

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