Geeks With Blogs

News Welcome to my programming blog. I am a software developer living in Hertfordshire, United Kingdom.

I've been a keen developer for over a decade, most of it spent on C#/.Net development with ever increasing amounts of Javascript and I am an avid biker as well.

Please feel free to leave a comment if you found a post useful :-).

My twitter handle is BikerDev.

My LinkedIn profile.
Ritesh Singh's Programming Blog .Net and more

The other day I noticed that although the ThreadPool class contains a method called QueueUserWorkItem there is no guarantee that it will run functions in the order that they are queued.

The code below was run on LinqPad and as you can see there are four methods Fast1, Fast2, Slow1 and Slow2. Even though I’ve called them in that order the ThreadPool is not running them in that order. Something to be aware of if you’re using the QueueUserWorkItem method.

 

QueueUserWorkItemCode

 

Each time I ran the code above the functions were called in a different order. The CPU on which this ran is a Core i7 quad core. Here’s one possible result…

 

QueueUserWorkItemResult

Posted on Sunday, December 7, 2014 12:18 PM C# | Back to top


Comments on this post: ThreadPool’s QueueUserWorkItem does not queue

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © BikerDev | Powered by: GeeksWithBlogs.net