AutomaticUpdater exception

I'm getting the following exception from AutomaticUpdater control when my application starts:

System.InvalidOperationException: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

Stack Trace: at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at wyDay.Controls.AutomaticUpdater.auBackend_ClosingAborted(Object sender, EventArgs e) at wyDay.Controls.AutomaticUpdaterBackend.updateHelper_PipeServerDisconnected(Object sender, UpdateHelperData e) at wyDay.Controls.UpdateHelper.bw_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e) at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg) at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack) at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

Looks like AutomaticUpdater calls Invoke on the owner form before the form's handle is created. You should wait until ownerForm.IsHandleCreated returns true before doing anything with the ownerForm. Please check this link:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx

"In the case where the control's handle has not yet been created, you should not simply call properties, methods, or events on the control. This might cause the control's handle to be created on the background thread, isolating the control on a thread without a message pump and making the application unstable."

Waiting for a fix

What version of the AutomaticUpdater are you using? Right click the AutomaticUpdater.dll in your app's binary folder, click Properties, and then look at the version.

2.6.16.0 from the latest wyBuild download.

I'll look into reproducing this.

It might be hard to reproduce. We have fairly large application that loads 20 assemblies, over 15 meg of .dll files. It takes several seconds to start. I got it into a state where I couldn't debug our app or start it outside of VS because of that exception in auBackend_ClosingAborted. Had to delete wyUpdate AU folder to get it working again. Didn't encounter that problem since then. We distributed beta version of our application that includes AutomaticUpdater to about 100 customers. Our application logs all errors to our server, so we will see if any customers encounter this issue.

Still, IsHandleCreated check is needed before Invoke to make sure it's safe to call Invoke...

We've fixed this in AutomaticUpdater 2.6.18.

We've fixed this in AutomaticUpdater 2.6.18.

Looks like it's still not fixed or maybe this is another related exception. We have published an update to our software that includes wyUpdate 2.6.18.4 and AutomaticUpdater 2.6.18.4. Here is the error some of our customers are getting:

System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at wyDay.Controls.AutomaticUpdater.auBackend_UpdateFailed(Object sender, FailArgs e) at wyDay.Controls.AutomaticUpdaterBackend.UpdateStepFailed(UpdateStepOn us, FailArgs args) at wyDay.Controls.AutomaticUpdaterBackend.updateHelper_PipeServerDisconnected(Object sender, UpdateHelperData e) at wyDay.Controls.UpdateHelper.ServerDisconnected() at wyDay.Controls.PipeClient.Read() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Well, this is a different exception, but we'll fix this as well.

Thank you Sam. I investigated this problem and here how it happens:

1. AutomaticUpdater detects new update, downloads it and shows that the update will be installed on next start.2. User shutdowns our application and starts it again.3. AutomaticUpdater starts wyUpdate when our application is started while our application is still loading.4. wyUpdate tries to update our application but our application is still loading.5. wyUpdate shows that our application is running and asks to terminate the process.6. auBackend_UpdateFailed in AutomaticUpdater is called and it calls Invoke on our main form. Exception is thrown because handle for our main form is not created yet (remember, our application is still loading).

Maybe AutomaticUpdater should not start wyUpdate immediately on application startup when the update is ready to be installed. I would suggest something like that:1. AutomaticUpdater detects that the update has to be installed and requests application shutdown by firing CloseAppNow, making sure form handle is created before firing the event of course.2. Application closes, and AutomaticUpdater in FormClosed event handler starts the update process by launching wyUpdate.

I don't want users to see wyUpdate "terminate process" dialog, it's very bad user experience. In our case it's shown because our application wasn't given enough time to fully load then shutdown before wyUpdate tried to update it.

We experience a similair problem. Is there any solution for it?

We use a splash win form window to allow user to make his options before loading the main window.Closing splash window causes main window to be loaded.

The wyUpdate widget is placed on the main window.

wyUpdate downloads updates. With next app start the follwoing expection is thrown:

System.InvalidOperationException was unhandledMessage: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

Any workaround?

We're working to fix this problem for the next version.

i am getting a similar exception

when uac is open in some users I get this exception.after automatic updater downloads if user restarts the app in the opening phase sometimes we see this exception.but the user gets the update successfully.

just there is an annoying exception.how can we avoid this?

11.29.2012 14:39:10 - Info:Generic exception handler from ExceptionManager.System.InvalidOperationException: Stack empty. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Stack`1.Pop() at wyDay.Controls.UpdateHelper.bw_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e) at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)11.29.2012 14:39:11 - Info:Generic exception handler from ExceptionManager.System.ObjectDisposedException: Cannot access a disposed object.Object name: 'MyFrmMain'. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at wyDay.Controls.AutomaticUpdater.auBackend_BeforeExtracting(Object sender, BeforeArgs e) at wyDay.Controls.AutomaticUpdaterBackend.ExtractUpdate() at wyDay.Controls.AutomaticUpdaterBackend.StartNextStep(UpdateStep updateStepOn) at wyDay.Controls.AutomaticUpdaterBackend.updateHelper_ProgressChanged(Object sender, UpdateHelperData e) at wyDay.Controls.UpdateHelper.ProcessReceivedMessage(UpdateHelperData data) at wyDay.Controls.UpdateHelper.SafeProcessReceivedMessage(Byte[] message) at wyDay.Controls.PipeClient.Read() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()