• home
  • forum
  • my
  • kt
  • download
  • How to prevent multiple instances of an app running

    Author: 2008-09-13 09:38:37 From:

    When you've done that, it should prompt you with a dialog box asking you what type of project you want to make. Choose Standard EXE and press open.

    First Step.

    Once you have done that, you should have something that looks like this:

    Step 2.

    We could now do some sort of design for this form. I will not. I won't because I can't be bothered and you might want to put this in your own project. You can put the code into the Form_Load procedure to make the code work when the application first runs.

    Double click on the form. It will come up with some code like this:

    Private Sub Form_Load()

    End Sub

    In the middle of this, insert this code

    If App.PrevInstance Then
    MsgBox "There is already another instance of this application running. This instance will now end."
    Unload Me
    End If

    You should now have this code

    Private Sub cmd_Calculate_Click()
    If App.PrevInstance Then
    MsgBox "There is already another instance of this application running. This instance will now end."
    Unload Me
    End If
    End Sub

    The App.PrevInstance code will return true if another instance of the app is running. So it's saying if the app is already open then display a messagebox; wait for the user to click OK and then Unload Me, which will end the app. Then it ends the If...Then...Else statement.

    You should now compile you application by going to the file menu and selecting, "Make Project1.exe" or something similar.

    When you've done this, run your app. Then run it again and when you run it the second time a messagebox should pop up with the text you chose.

    When you are done with your application, exit out of it and save.

     

    Download Project

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      .NET (8)
      Buttons (3)
      Database Related (7)
      Date and Time (1)
      Development (3)
      Error Handling (2)
      File Manipulation (5)
      Introduction to Visual Basic (20)
      Miscellaneous (3)
      Multimedia (10)
      Networking (10)
      Security (1)
      VB Script (6)

    New

    Hot