J
John
Hi
Is there a way to restart a winform app in case of a serious error?
Thanks
Regards
Is there a way to restart a winform app in case of a serious error?
Thanks
Regards
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 = 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 = 1
Dim b As Integer = 0
Dim c As Integer
c = a / b
Catch
' Determine error is occured
haderror = 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 = 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 = 1
Dim b As Integer = 0
Dim c As Integer
c = a / b
Catch
MsgBox("Error! Restarting application...")
Me.Close()
System.Diagnostics.Process.Start("WindowsApplication1.exe")
End Try
Thanks,
Onur Güzel