Delegate.BeginInvoke vs ThreadPool.QueueUserWorkItem

3 Comments »

ThreadPool is performance-wise faster.

ThreadPool is fire and forget in the sense that BeginInvoke should always be paired with EndInvoke because exceptions are passed to the EndInvoke and should be handled here to avoid the exceptions lingering in memory.

If you don’t care about exceptions and have a relatively simple delegate that should be invoked, use ThreadPool.

If you have more complex delegates where things could go wrong that you care about, use Delegate.BeginInvoke/EndInvoke.

An example of how to use the ThreadPool.QueueUserWorkItem and lambda expressions:


ThreadPool.QueueUserWorkItem(callback => SomeMethod(someArgument));

Alternatively:


WaitCallback waitCallback = new WaitCallback(callback => { x => x*x});

ThreadPool.QueueUserWorkItem(waitCallback);
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

CLR profiler for memory leaks

1 Comment »

http://www.microsoft.com/downloads/details.aspx?familyid=86ce6052-d7f4-4aeb-9b7a-94635beebdda&displaylang=en

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

String concatenation optimization

2 Comments »

A discussion on the performance of various ways of concatenating string in c#.

Conclusion seems to be StringBuilder provides better performance for larger concatenation iterations. String.Format does not.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comparison of foreach and List.ForEach

No Comments »
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Sorting links

No Comments »

http://www.sorting-algorithms.com/ holds a nice overview of the most common sorting algorithms.

http://www.csharp411.com/c-stable-sort/show a demonstration of an insertion sort algorithm done in C#.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...