Solved

Check if application already running in VB .NET

Posted on 2004-09-28
1
178 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

634 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