[RESOLVED] programmatically restart app after end
My Idea (which may be not good) was to at form unload add....
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim RetVal
RetVal = ShellExecute(vbNull, "open", App.Path & "\" & App.EXEName, vbNullString, vbNullString, 1)
End Sub
But it didn't work coz i check for app.previnstance in form load event and end it if i find one. And the above method works so fast that it loads the instance before the oriinal app has been unloaded so the app.previnstance gets true and ends.
Then my 2nd method was to let the 2nd opening instance app to wait a little bit for the original app to completely unload and i achived it using timer to wait a few seconds and then check for the instance, but ironically after few seconds when the timer gets activated even though the original app has been unloaded the app.previnstance gets true and the 2nd instance also gets ended????????
Does anybody has a solution?
PS: I don't want to use batch files or another app for restarting etc...
Re: programmatically restart app after end
Without giving any thought to your problem why don't you have two app? 0.exe and 1.exe. Both the same but different EXE names. Then Shell the opposite name of the one running by using XOR on the app name
Re: programmatically restart app after end
Why are you trying to restart it on end? Hopefully this is just some special case and not normal behaviour else the user would never be able to terminate your program using normal methods and may even have trouble shutting down or restarting thier machine. Doesn't seem like a very good idea. If I were to install a program that did this I will kill the process then delete the files from my system.
Re: programmatically restart app after end
@jmsrickland it wont look nice for the user to see 2 copies ofyour app
@DataMiser it is very different situation
Re: programmatically restart app after end
@jmsrickland it wont look nice for the user to see 2 copies ofyour app
@DataMiser it is very different situation
Re: programmatically restart app after end
Quote:
Originally Posted by
ufo973
@jmsrickland it wont look nice for the user to see 2 copies ofyour app
@DataMiser it is very different situation
How will users see two copies? In the Task bar or on the screen? If on the screen then both copies look identical; if task bar then yes.
Re: programmatically restart app after end
You could put a switch to bypass app.previnstance when you go to load app the second time and load it before you enter the Unload event.
Dim AllowPrevInstance As Boolean
At startup
If Not AllowPrevInstance Then
'
' your code to check for app.previnstance
'
End If
Your code to load 2nd instance
Private Sub SomeSubRightBeforeUnload()
AllowPrevInstance = True
'
' Your code to load 2nd instance
'
End Sub
Re: programmatically restart app after end
Re: programmatically restart app after end
Quote:
Originally Posted by
coolcurrent4u
Thanks Alot it is what i wanted :)
PS:How to mark a thread Resolved?
Re: programmatically restart app after end
Quote:
Originally Posted by
ufo973
Thanks Alot it is what i wanted :)
PS:How to mark a thread Resolved?
At the top of the thread is the "Thread tools" menu. Select it then go to "Mark thread resolved".