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

I have "Applications.PrevInstance" in VB 6 code, which I am trying to upgrade to .NET using VS 2008. Apparently, this code is no longer valid. Does anyone have any ideas for an updated solution? TIA

+4
source share
2 answers

Look 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 
+7
source
 Function PrevInstance() As Boolean If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then PrevInstance = True Else UserName = Environ("UserName") Computername = Environ("COMPUTERNAME") PrevInstance = False End If Dim i, n As Integer, RepForm As String For i = My.Application.OpenForms.Count - 1 To 1 Step -1 RepForm = My.Application.OpenForms.Item(i).Name For n = My.Application.OpenForms.Count - 1 To 1 Step -1 If My.Application.OpenForms.Item(n).Name = My.Application.OpenForms.Item(i).Name And n > i Then My.Application.OpenForms(i).Close() PrevInstance = True Exit Function End If Next n Next i End Function 
0
source

All Articles