0

how to check the application is already running using vb.net,if the application is running switch to that application how to do that using vb.net..?

Please help me

Thanks in advance..

Public Function IsProcessRunning(ByVal name As String) As Boolean
    For Each clsProcess As Process In Process.GetProcesses()
        If clsProcess.ProcessName.StartsWith(name) Then
            Return True
        End If
    Next
    Return False
End Function
Private Sub adxcmbSwitchtoDLtool_Click(ByVal sender As System.Object) Handles adxcmbSwitchtoDLtool.Click
    Dim path As String = "D:\SRIVANI\DLEWISSCM\DictaSolicitor\bin\Debug\DictaSolicitor.EXE"
    If IsProcessRunning(path) = True Then

    Else
        Process.Start(path)
    End If
end sub

i wrote code like that if i click on the button my application is open and again i click on the button again my application is running..how many times i click the button those many times the application is running how to check the opened application and switch to the application............

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
Srivani
  • 19
  • 1
  • 2
  • 7
  • 1
    Possible duplicate of http://stackoverflow.com/questions/391339/how-to-make-sure-that-there-is-one-instance-of-the-application-is-running – LittleBobbyTables - Au Revoir Jul 18 '13 at 13:12
  • 1
    [Overview of the Visual Basic Application Model](http://msdn.microsoft.com/en-us/library/w3xx6ewx(v=vs.110).aspx): "The Visual Basic Application model makes it easy to create a single-instance application. A single-instance application differs from a normal application in that only one instance of the application can be running at a time. An attempt to launch another instance of a single-instance application results in the original instance being notified ..." – Damien_The_Unbeliever Jul 18 '13 at 13:12
  • @Srivani: Please edit that code into your question. – Ry- Jul 18 '13 at 15:22

1 Answers1

5

Just enable the "Make single-instance application" checkbox in your application properties.

sloth
  • 99,095
  • 21
  • 171
  • 219
  • while enable the "Make single-instance application" checkbox in my application properties,i am getting the following error..startup object must be a form when "Enable application framework" is checked.how to resolve it through coding.......please help me.. – Srivani Jul 19 '13 at 08:00
  • i make the application is single instance application but still i am facing the same problem,how to resolve it.. – Srivani Jul 22 '13 at 07:19