Hi

Is there a way to restart a winform app in case of a serious error?

Thanks

Regards

Re: Restarting app by kimiraikkonen

kimiraikkonen
Mon Jun 09 03:41:28 CDT 2008

On Jun 8, 5:30 pm, "John" <i...@nospam.infovis.co.uk> wrote:
> Hi
>
> Is there a way to restart a winform app in case of a serious error?
>
> Thanks
>
> Regards

Hello,
A longer way which you may consider:
' My sample...

Public Class Form1
Dim haderror As Boolean =3D False

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
' Do some invalid stuff
Dim a As Integer =3D 1
Dim b As Integer =3D 0
Dim c As Integer
c =3D a / b

Catch
' Determine error is occured
haderror =3D True
' Close app
Me.Close()

End Try
End Sub

Private Sub Form1_closed(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

If haderror =3D True Then
' Start application again
System.Diagnostics.Process.Start("WindowsApplication1.exe")
End If
End Sub
End Class

or..just put Process.Start into Catch block where you know when an
error may happen without using Form_Closed event:

Try
' Do some invalid stuff
Dim a As Integer =3D 1
Dim b As Integer =3D 0
Dim c As Integer
c =3D a / b
Catch
MsgBox("Error! Restarting application...")
Me.Close()
System.Diagnostics.Process.Start("WindowsApplication1.exe")
End Try


Thanks,

Onur G=FCzel

Re: Restarting app by JR

JR
Thu Jun 19 08:35:33 CDT 2008

On 9 jun, 10:41, kimiraikkonen <kimiraikkone...@gmail.com> wrote:
> On Jun 8, 5:30 pm, "John" <i...@nospam.infovis.co.uk> wrote:
>
> > Hi
>
> > Is there a way to restart a winform app in case of a serious error?
>
> > Thanks
>
> > Regards
>
> Hello,
> A longer way which you may consider:
> ' My sample...
>
> Public Class Form1
> Dim haderror As Boolean =3D False
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Try
> ' Do some invalid stuff
> Dim a As Integer =3D 1
> Dim b As Integer =3D 0
> Dim c As Integer
> c =3D a / b
>
> Catch
> ' Determine error is occured
> haderror =3D True
> ' Close app
> Me.Close()
>
> End Try
> End Sub
>
> Private Sub Form1_closed(ByVal sender As System.Object, ByVal e As
> System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
>
> If haderror =3D True Then
> ' Start application again
> System.Diagnostics.Process.Start("WindowsApplication1.exe")
> End If
> End Sub
> End Class
>
> or..just put Process.Start into Catch block where you know when an
> error may happen without using Form_Closed event:
>
> Try
> ' Do some invalid stuff
> Dim a As Integer =3D 1
> Dim b As Integer =3D 0
> Dim c As Integer
> c =3D a / b
> Catch
> MsgBox("Error! Restarting application...")
> Me.Close()
> System.Diagnostics.Process.Start("WindowsApplication1.exe")
> End Try
>
> Thanks,
>
> Onur G=FCzel

Also take a look at aplication events specialy UnhandledException

Re: Restarting app by RobinS

RobinS
Fri Jun 20 10:54:20 CDT 2008

Try Application.Restart.

RobinS.
GoldMail.com

"John" <info@nospam.infovis.co.uk> wrote in message
news:OvheCRXyIHA.2064@TK2MSFTNGP05.phx.gbl...
> Hi
>
> Is there a way to restart a winform app in case of a serious error?
>
> Thanks
>
> Regards
>
>