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).
Here is the Exception Detail (partially in French):
System.Reflection.TargetParameterCountException was unhandled Message=Nombre de paramètres incorrects.
Source=mscorlib StackTrace: à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) à System.Delegate.DynamicInvokeImpl(Object[] args) à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) à System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) à System.Windows.Threading.DispatcherOperation.InvokeImpl() à System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) à System.Threading.ExecutionContext.runTryCode(Object userData) à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Windows.Threading.DispatcherOperation.Invoke() à System.Windows.Threading.Dispatcher.ProcessQueue() à System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) à MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) à MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) à System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) à System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) à System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) à MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) à MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) à System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) à System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) à System.Windows.Threading.Dispatcher.Run() à System.Windows.Application.RunDispatcher(Object ignore) à System.Windows.Application.RunInternal(Window window) à System.Windows.Application.Run(Window window) à System.Windows.Application.Run() à WpfApplication3.App.Main() dans h:\razor\documents\visual studio 2010\Projects\WpfApplication3\WpfApplication3\obj\x86\Debug\App.g.cs:ligne 0 à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart() InnerException:
Thanks for any help.