Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much time spent in a .NET Thread?

I have a multi-threaded application with (4) thread i want to know how much processing time spent in threads. I've created all these threads with ThreadPool

Thread1 doing job1
Thread2 doing job2
..
..

result would be:
Thread1 was running in 12 millisecond
Thread2 was running in 20 millisecond

I've actually download a web page in a job that each job is processing in one thread i want to know how much time it takes a web page is downloaded (without the affection of other threads context switch in calculated time

like image 306
Ehsan Avatar asked Oct 04 '10 09:10

Ehsan


People also ask

Can you run out of threads C#?

If your ThreadPool runs out of threads two things may happen: All opperations are queued until the next resource is available. If there are finished threads those might still be "in use" so the GC will trigger and free up some of them, providing you with new resources.

What is thread life cycle in C#?

The life cycle of a thread is started when instance of System. Threading. Thread class is created. When the task execution of the thread is completed, its life cycle is ended.

What is the maximum number of threads in C#?

The maximum allowed number of processing threads in a pool is 1023. The pool allocates a maximum of 1000 threads in an I/O operation. To get maximum number of threads, you can use the GetMaxThreads method of the ThreadPool static class.

What is a .NET thread?

Threads are tasks that can run concurrently to other threads and can share data. When your program starts, it creates a thread for the entry point of your program, usually a Main function. So, you can think of a "program" as being made up of threads.


1 Answers

I found this code on codeproject:

http://www.codeproject.com/KB/dotnet/ExecutionStopwatch.aspx

Try it and report back ;)

like image 71
Marcus Johansson Avatar answered Oct 19 '22 10:10

Marcus Johansson