Reputation: 66320
if I have a dispatcher invoking in background like this:
Application.Current.Dispatcher.BeginInvoke(new Action(() => MethodToCall()), DispatcherPriority.Background);
Should I have wrap the code above inside a Try & catch or place the try & catch inside the MethodToCall()
method?
Many Thanks,
Upvotes: 1
Views: 5495
Reputation: 3534
Hi BeginInvoke will Execute your Method in anoster Stack. So a try-catch around "Application.Current.Dispatcher.BeginInvoke" will not work.
You need to do something like this:
Application.Current.Dispatcher.BeginInvoke(() => {
try
{
MethodToCall();
}
catch
{
//handle
}
), DispatcherPriority.Background);
or simply in "MethodToCall".
As ChrisF stated.
Upvotes: 3
Reputation: 137128
If you really have a case for catching a specific exception then the try { } catch
should be placed inside MethodToCall
.
Upvotes: 4