Adriano Zawadzki
Adriano Zawadzki

Reputation: 174

How long a thread is alive in c#

Is there any way to verify how long a Thread is alive?

I want to know how long my System.Threading.Thread.CurrentThread is alive in a ASP.NET page.

Upvotes: 0

Views: 1816

Answers (2)

Guffa
Guffa

Reputation: 700342

The thread will be alive until the IIS worker thread is recycled, or the server is restarted/turned off. The thread will be reused to handle more requests, so the lifetime of the thread can not be used to determine how long time it takes to handle a request (which I suspect that you really want to find out).

Besides, a single request can be handled by different threads. At certain points in the page life cycle, the execution can be taken over by another thread.

So, how long the thread has been alive is not relevant for the ASP.NET page.

Upvotes: 2

Yahia
Yahia

Reputation: 70369

AFAIK there is no direct method to achieve that...

BUT you could do this:

This gives you DateTime... which you would substract from DateTime.Now to get a TimeSpan... there you can access Ticks etc.

Upvotes: 1

Related Questions