IF statement when program self terminates
Page 1 of 14 Replies - 224 Views - Last Post: 08 November 2012 - 01:44 PM
#1
IF statement when program self terminates
Posted 07 November 2012 - 01:32 PM
Hey, i was wondering if the was anyway to do an if statement just as the program self terminates, i would like to use this so that if the program crashes and self termibates, just as its doing this it will create a crashlog in a certain location, so an if statement would be like If program crashing = true, save crashlog to path, (thats just psuedo code
). so i was wondering if its possible, and if it is can you give me some links to the msdn pages on the commands/functions to use, thanks
Replies To: IF statement when program self terminates
#2
Re: IF statement when program self terminates
Posted 07 November 2012 - 01:52 PM
Not real sure how you would do it. What would you put in it? I mean, the program crashed so I'm thinking it's not going to care what you want at that point 
Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.
Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.
Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.
Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.
#3
Re: IF statement when program self terminates
Posted 07 November 2012 - 02:27 PM
CharlieMay, on 07 November 2012 - 01:52 PM, said:
Not real sure how you would do it. What would you put in it? I mean, the program crashed so I'm thinking it's not going to care what you want at that point 
Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.
Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.
Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.
Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.
Thats quite a good method but it would say that it crashed if you used windows 7's right click on the program in the taskbar and use close program. So basically the only way they'd be able to shut it down without a crashlog would be to use a close button on the form, which 90% of people wont do
#4
Re: IF statement when program self terminates
Posted 07 November 2012 - 02:57 PM
No, if a user right-clicks on the taskbar icon and selects Close or Exit, the program will go through the same code as it would if the user clicks a close button or the Close icon in the Titlebar, or even if the program gets to an End statement.
The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.
The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
' Do stuff here
End Sub
#5
Re: IF statement when program self terminates
Posted 08 November 2012 - 01:44 PM
lar3ry, on 07 November 2012 - 02:57 PM, said:
No, if a user right-clicks on the taskbar icon and selects Close or Exit, the program will go through the same code as it would if the user clicks a close button or the Close icon in the Titlebar, or even if the program gets to an End statement.
The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.
The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
' Do stuff here
End Sub
Thanks, helped a lot, and thanks to charlie as well for the initial idea
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|