In my WPF application, I want to do some work in a non-UI thread so as to avoid the UI from become not-responding. For that I did this:
var caller = new AsyncMethodCaller<Pattern>(this.SetPatternType);
caller.BeginInvoke(_patterns, null, null);
And the delegate is defined as,
public delegate void AsyncMethodCaller<in T>(IEnumerable<T> data);
My question is:
Does BeginInvoke()
create a new thread and the callback SetPatternType
runs in it? If so, how long this thread last?
Is this approach good in general? If not, what is wrong with it? And what potential problem(s) might I face?
I'm using C# 4.0 and Visual Studio 2010.
EDIT:
Also I need few guidelines regarding these:
When I should create a new thread myself and when should I make use of BeginInvoke()
? And when should I use DispatcherObject.Dispatcher.BeginInvoke()
object?