Tuesday, September 14, 2004

VJs Tip Of The Day - September 14th 2004

Quick MultiThreading
This is some real quick good info for specific scenarios... If you are writing some workflow logic of yours and in-between you realize that you want to perform some tasks which would be time consuming but actually are also apart from your actual business logic and so you would not want your business logic to waste on performance by waiting for those tasks to complete... Some of the examples of such tasks would be printing, cleaning back-end, doing logging or tracing functionality etc...
Well this is when the System.Threading.ThreadPool class comes real handy... There is a static method called QueueUserWorkItem... You can call this method with the method that you want to execute Asynchronously... The Threadpool will use the first available thread to process your request... Now your main business logic does not need to wait for this function to finish...
Now this function can as well give a call back but then it depends upon your requirements...
Read more about it on MSDN... Click Here...
PS: This tip is a result of my discussions with Matt, a colleague of mine... We often discuss interesting technical stuff in our "Leisure At Work" (LAW can never be illegal right!!)

Note: Caution on multithreading... You should know that if different threads are gonna use the same resource then multithreading might cause performance hits as well... Thanks Kathleen for reminding...

No comments: