Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Application.PrevInstance in VB 6.0 to VB.NET?

I have 'Applications.PrevInstance' in VB 6 code that I am trying to upgrade to .NET using VS 2008. Apparently this code is no longer valid. Does anyone have any ideas about upgraded solution? TIA

like image 638
Daniel Grindstaff Avatar asked Feb 26 '23 07:02

Daniel Grindstaff


1 Answers

See here:

http://www.knowdotnet.com/articles/previnstance.html

Public Sub Main()
   If PrevInstance() Then Exit Sub

   ' continue with your application
   UserName = Environ("UserName")
   ComputerName = Environ("COMPUTERNAME")

End Sub

Function PrevInstance() As Boolean
  If UBound(Diagnostics.Process.GetProcessesByName _
     (Diagnostics.Process.GetCurrentProcess.ProcessName)) _
     > 0 Then
     Return True
  Else
     Return False
  End If
End Function
like image 102
Robert Harvey Avatar answered Mar 13 '23 08:03

Robert Harvey