Results 1 to 10 of 10

Thread: [RESOLVED] programmatically restart app after end

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    126

    Resolved [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...

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; Sep 7th, 2012 at 05:16 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    126

    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    126

    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

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: programmatically restart app after end

    Quote Originally Posted by ufo973 View Post
    @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.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; Sep 7th, 2012 at 06:05 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: programmatically restart app after end

    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2011
    Posts
    126

    Re: programmatically restart app after end

    Quote Originally Posted by coolcurrent4u View Post
    Thanks Alot it is what i wanted

    PS:How to mark a thread Resolved?

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: programmatically restart app after end

    Quote Originally Posted by ufo973 View Post
    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".
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width