469,927 Members | 1,654 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Restarting app

Hi

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

Thanks

Regards
Jun 27 '08 #1
7 1089
John wrote:
Hi

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

Thanks

Regards

Application.Restart()
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Jun 27 '08 #2
On Jun 8, 5:30 pm, "John" <i...@nospam.infovis.co.ukwrote:
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("WindowsApplicati on1.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("WindowsApplicati on1.exe")
End Try
Thanks,

Onur Güzel
Jun 27 '08 #3
JR
On 9 jun, 10:41, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jun 8, 5:30 pm, "John" <i...@nospam.infovis.co.ukwrote:
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("WindowsApplicati on1.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("WindowsApplicati on1.exe")
End Try

Thanks,

Onur Güzel
Also take a look at aplication events specialy UnhandledException
Jun 27 '08 #4
Try Application.Restart.

RobinS.
GoldMail.com

"John" <in**@nospam.infovis.co.ukwrote in message
news:Ov**************@TK2MSFTNGP05.phx.gbl...
Hi

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

Thanks

Regards

Jun 27 '08 #5
Is there a downside to Application.Restart?

I have an application that finishes up at midnight, wraps up everything,
produces and FTPs a report and then does some gyrations to get ready for
tomorrow.

Application.Restart would be great as I could dump all of the "get ready
for the new day" code and just start up again. When it restarts it
reads the input data file and sets up everything just right.

I just don't want to throw away a bunch of memory every midnight or
cause some other catastrophe by restarting every 24 hours.

Otherwise, it saves me maintaining a bunch of code which has caused
problems in the past with date changing and data manipulation to keep
everything happy.

Mike

On Fri, 20 Jun 2008 08:54:09 -0700, in
microsoft.public.dotnet.languages.vb "RobinS" <ro****@imnottelling.com>
wrote:
>Try Application.Restart.

RobinS.
GoldMail.com

"John" <in**@nospam.infovis.co.ukwrote in message
news:Ov**************@TK2MSFTNGP05.phx.gbl...
>Hi

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

Thanks

Regards

Jun 27 '08 #6
Ju********@home.net wrote:
Is there a downside to Application.Restart?

I have an application that finishes up at midnight, wraps up everything,
produces and FTPs a report and then does some gyrations to get ready for
tomorrow.
I use Application.Restart for all my software in cases where there's
been an unexpected error (after notifying the User) and after my own
software update routines have completed.

Many of these applications run 24/7 and I have never experienced any
issues with memory leaks or alike after calling this method. There are
probably tests that could be done to determine this.

Just the same, I do however feel that your intended use is not something
I would do. Like you, I have software that needs to "age" data once a
new day begins but I always develop that code into procedures that can
be called either by a Timer or Form_Load, so it doesn't matter which
does it. To me that would be more professional than just restarting the
application to achieve a new-day type result.

Just my opinion.
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Jun 27 '08 #7
Yeah, using Application.Restart does feel somewhat like incrementing a
Do loop variable inside the loop. Legal, but....

Thanks for the input. I may do it, I may not. I have been changing a
lot of how the app works and when I do, frequently I have to change it
in the startup and in the midnight data age off and then in the
presentation routines to point to where the data is now. I finally got
to the point that I don't like the original design.

Changing 2 or more pieces of code just leads to error when you have to
change multiple routines which are doing about the same thing. There
have been times when I "remembered" doing something in the second of two
but I was actually remembering doing it in the first of two and left it
out of the second one. I just like to not have that happen.

Thank goodness I don't sell this little beast (no irate users) and I
have a backup for the data if it explodes so I can play around with it a
little bit without great problem. My penalty is having to do some
reformatting of the data if I get it from the backup facility so I do
try to keep it up and running 24x7.

My real goal is to split it into two pieces. One will simply data
collect, write a file and respond to requests for data from the UI piece
that will show the data. Then they are totally separate and I won't
even think of doing a restart since the process will be completely
linear on the collector/server end and transaction based on the UI piece
of the pair. Now where did I put that book on Remoting.....?

Mike

On Fri, 27 Jun 2008 13:45:29 +1000, in
microsoft.public.dotnet.languages.vb ShaneO <sp****@optusnet.com.au>
wrote:
>Ju********@home.net wrote:
>Is there a downside to Application.Restart?

I have an application that finishes up at midnight, wraps up everything,
produces and FTPs a report and then does some gyrations to get ready for
tomorrow.
I use Application.Restart for all my software in cases where there's
been an unexpected error (after notifying the User) and after my own
software update routines have completed.

Many of these applications run 24/7 and I have never experienced any
issues with memory leaks or alike after calling this method. There are
probably tests that could be done to determine this.

Just the same, I do however feel that your intended use is not something
I would do. Like you, I have software that needs to "age" data once a
new day begins but I always develop that code into procedures that can
be called either by a Timer or Form_Load, so it doesn't matter which
does it. To me that would be more professional than just restarting the
application to achieve a new-day type result.

Just my opinion.
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Phil S | last post: by
3 posts views Thread by Jerry Boone | last post: by
1 post views Thread by Scott Lezberg | last post: by
9 posts views Thread by woolley.dean | last post: by
9 posts views Thread by walterbyrd | last post: by
4 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.