Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check if application already running in VB .NET

Posted on 2004-09-28
1
Medium Priority
?
183 Views
Last Modified: 2013-12-26
The App.PrevInstance function is deprecated and no longer usable in .NET.  There is no equivalent, but the same result can be obtained via:

Public Function PrevInstance() As Boolean
  If Diagnostics.Process.GetProcessesByName _
     (Diagnostics.Process.GetCurrentProcess.ProcessName) _
               .Length > 1 Then
     Return True
  Else
     Return False
  End If
End Function

My problem is that whenever I make a call to the Diagnostics.Process.xxx objects, my application stalls and needs to be manually end tasked.  For trouble shooting purposes I have tried:
msgbox(Diagnostics.Process.GetCurrentProcess.ProcessName)
This also freezes the application.  Even a completely empty application with only one form and with this msgbox line in the form load function freezes.  Any ideas?

On another note, my application is one that runs solely in the system tray as a system tray icon, with no visible windows.  The way I have accomplished this is by setting the form that loads with the project to start minimized and then doing me.hide() on form load.  Is this a good/the right way to do this?

Thanks.
0
Comment
Question by:JeffN825
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 12176534
This worked correctly for me:

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If PrevInstance() Then
            MsgBox("another instance is running")
        End If
    End Sub

    Private Function PrevInstance() As Boolean
        If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

End Class
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question