dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] VS 2017 problem between application.restart and GetCurrentProcess

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Resolved [RESOLVED] VS 2017 problem between application.restart and GetCurrentProcess

    when i enter to the programm i check to see if the program is already running.
    Now,when i need to restart the programm i use application.restart (in a button on form).
    problem is that if i restart the programm then i cant check to see if the programm is already running beacuse its displaying me the message that the programm is already runing.
    what can i do?
    this is in the Form load
    Code:
     If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) > 0 Then
         MessageBox.Show("programm is already running", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
     End if
    any suggestion will be welcomed
    salsa

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,313

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    Quote Originally Posted by salsa31 View Post
    when i enter to the programm i check to see if the program is already running.
    Now,when i need to restart the programm i use application.restart (in a button on form).
    problem is that if i restart the programm then i cant check to see if the programm is already running beacuse its displaying me the message that the programm is already runing.
    what can i do?
    this is in the Form load
    Code:
     If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) > 0 Then
         MessageBox.Show("programm is already running", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
     End if
    any suggestion will be welcomed
    salsa
    What comes after 0?

    Ignoring that since it's not clear what your intentions are maybe a single instance application is what you are after?

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    I was thinking that you could pass an environment variable that you modify and check for so that you skip the already running test.
    But, it might be easier to just create a temporary file that you check for when you start up. If the file is not there, you check to see if the application is already running. If the file is there, you delete the file and don't check to see if the application is already running.

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,313

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    God this forum. Once again lost an entire post. Summery is I presume it is a deadlock not pumping the message que. Invoke waits to return. It cannot. The constant should also be so i believe is PBM_SETSTATE &H410

    *link removed see if can post

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    Quote Originally Posted by ident View Post
    What comes after 0?
    exit sub

  6. #6

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    Quote Originally Posted by passel View Post
    I was thinking that you could pass an environment variable that you modify and check for so that you skip the already running test.
    But, it might be easier to just create a temporary file that you check for when you start up. If the file is not there, you check to see if the application is already running. If the file is there, you delete the file and don't check to see if the application is already running.
    can you show me how?

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,333

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    Quote Originally Posted by salsa31 View Post
    can you show me how?
    Well, I was thinking something along these lines.
    Code:
    Public Class Form1
      Private tmpFile As String = IO.Path.Combine(IO.Path.GetTempPath(), "RestartingMyApp.Flag")
    
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(tmpFile) Then  'we're doing a restart, so don't check for previous instance
          IO.File.Delete(tmpFile)        '  delete the file flagging the restart 
        Else
          If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) > 0 Then
            MessageBox.Show("programm is already running", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.Close()
          End If
        End If
    
      End Sub
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'I'm restarting so flag the fact.
        Dim fs As IO.FileStream = IO.File.Create(tmpFile)
        fs.Close()
        Application.Restart()
      End Sub
    
    End Class
    But, as a simple example this doesn't recreate your issue so is not a valid test.
    Even without the addition of the temporary file code, the UBound check was never triggered. The original instance closed and a new one was started without overlap. I guess your code must be more complicated, and the running app doesn't close down completely before the new one is started.

    I tried forcing the situation by restarting a second instance manually, but the UBound check didn't see a second instance at that point in the code, so would allow a second instance to start up. It wouldn't allow a third, but it didn't trigger on the second. I don't know at what point in your code you have that check so that it works for you. I suppose if I added it to the Shown event, perhaps it would work, but I would prefer it detected the second startup before it flashed the form.

  8. #8
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,313

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    But why Is this instance already running?

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,009

    Re: VS 2017 problem between application.restart and GetCurrentProcess

    tnx passel ill try it

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width