Reputation: 8526
TargetParameterCountException: Parameter count mismatch.
What's going on here please?
After the method finish, this error is thrown.
I already tried some other topics, but my case is different.
Any clue?
I am using this Dispatcher, because I had a cross thread problem.
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (backgroundWorker.CancellationPending == true)
{
e.Cancel = true;
return;
}
e.Result = ...;
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
(RunWorkerCompletedEventHandler)delegate
{
image1.Source = (BitmapImage)e.Result;
});
}
Upvotes: 0
Views: 1289
Reputation: 185072
The RunWorkerCompletedEventHandler
delegate expects parameters, which you do not provide (or use), you could probably do with changing it to an Action
:
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate
{
image1.Source = (BitmapImage)e.Result;
});
If you must use the RunWorkerCompletedEventHandler
(which is pointless) you could call the respective BeginInvoke
overload and provide an empty array of two objects which represents sender and event-args:
Application.Current.Dispatcher.BeginInvoke((RunWorkerCompletedEventHandler)delegate
{
image1.Source = (BitmapImage)e.Result;
}, DispatcherPriority.Normal, new object[2]);
Upvotes: 1