VB.NET Application.Exit not closing forms opened using ShowDialog

829 Views Asked by At

I have a .Net application with multiple forms invoked using form.ShowDialog(). When I do Application.Exit, the application is not closing all the forms.

When I try to do an explicit Form.Close I am getting an error from WinForms as below

at Microsoft.AGL.Common.MISC.HandleAr(PAL_ERROR ar) at System.Windows.Forms.Form._CloseModal() at System.Windows.Forms.Form.Close() at

1

There are 1 best solutions below

2
On

As @CharithJ states in this answer (paraphrased):

Cancel the background worker and send an argument to the BackgroundWorker RunWorkerCompleted event to identify that time has expired. From that event you can call Application.Exit() just fine.