WPF ProgressBar - TargetParameterCountException

Posted by Dr_Asik on Stack Overflow See other posts from Stack Overflow or by Dr_Asik
Published on 2010-06-18T03:13:44Z Indexed on 2010/06/18 3:23 UTC
Read the original article Hit count: 248

Filed under:
|
|

I am making my first WPF application, where I use the Youtube .NET API to upload a video to Youtube using the ResumableUploader.

This ResumableUploader works asynchronously and provides an event AsyncOperationProgress to periodically report its progress percentage.

I want a ProgressBar that will display this progress percentage. Here is some of the code I have for that:

void BtnUpload_Click(object sender, RoutedEventArgs e) {
    // generate video

    uploader = new ResumableUploader();
    uploader.AsyncOperationCompleted += OnDone;
    uploader.AsyncOperationProgress += OnProgress;
    uploader.InsertAsync(authenticator, newVideo.YouTubeEntry, new UserState());
}

void OnProgress(object sender, AsyncOperationProgressEventArgs e) {
    Dispatcher.BeginInvoke((SendOrPostCallback)delegate {
        PgbUpload.Value = e.ProgressPercentage;
    }, DispatcherPriority.Background, null);
}

Where PgbUpload is my progress bar and the other identifiers are not important for the purpose of this question.

When I run this, OnProgress will be hit a few times, and then I will get a TargetParameterCountException. I have tried several different syntax for invoking the method asynchronously, none of which worked. I am sure the problem is the delegate because if I comment it out, the code works fine (but the ProgressBar isn't updated of course).

Thanks for any help.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf