Solved

Check if application already running in VB .NET

Posted on 2004-09-28
1
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 119
vb6 connector to mongodb 2 163
Recommendation vb6 to vb.net or others 14 241
VB6 calling COM DLL written in Visual Studio 2003 6 58
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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