Reputation: 174
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
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
Reputation: 70369
AFAIK there is no direct method to achieve that...
BUT you could do this:
ProcessThreadCollection
of the current Process
with Process.GetCurrentProcess().Threads
GetCurrentThreadId
(pinvoke since you need the native Thread ID!)ProcessThread.StartTime
to get the Starttime of the current ThreadThis gives you DateTime
... which you would substract from DateTime.Now
to get a TimeSpan
... there you can access Ticks
etc.
Upvotes: 1