G
Guest
Has anyone encountered the following problem
I' trying to prevent my program starting up twice. In my PrevInstance function I call the function Diagnostics.Process.GetCurrentProcess to retreive the processname. This does not work. This function hangs on my pc. If I try the same code on another PC (both XP) the same code works fine
I've tried to hard code the processName but then it will hang on the next line
myProcesses = Diagnostics.Process.GetProcessesByName(procName
(See code below
Does anyone know what may be the cause and how to solve this problem
Imports System.Runtime.InteropService
Public Class Global
<DllImport("user32.dll")> Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolea
End Functio
<DllImport("User32.dll")> Private Shared Function GetWindowLong(ByVal HWND As IntPtr, ByVal Index As Integer) As Intege
End Functio
Private Const SW_RESTORE As Integer =
Private Const GWL_STYLE As Integer = -1
Private Const WS_MINIMIZE As Integer = &H2000000
Public Shared Sub Main(
Dim PrevProcessID As Integer = PrevInstance(
If PrevProcessID = -1 The
Application.Run(New Form1
Els
AppActivate(PrevProcessID
End I
End Su
Private Shared Function PrevInstance() As Intege
Dim myProcesses As Process(
Dim localProcess As Process = Diagnostics.Process.GetCurrentProces
Dim procName As String = localProcess.ProcessNam
myProcesses = Diagnostics.Process.GetProcessesByName(procName
If UBound(myProcesses) > 0 The
Dim otherProcess As Proces
If myProcesses(0).Id = Process.GetCurrentProcess.Id The
otherProcess = myProcesses(1
Els
otherProcess = myProcesses(0
End I
Dim result As Intege
result = GetWindowLong(otherProcess.MainWindowHandle, GWL_STYLE
If (result And WS_MINIMIZE) = WS_MINIMIZE The
ShowWindow(otherProcess.MainWindowHandle, SW_RESTORE
End I
Return otherProcess.I
Els
Return -
End I
End Functio
End Class
I' trying to prevent my program starting up twice. In my PrevInstance function I call the function Diagnostics.Process.GetCurrentProcess to retreive the processname. This does not work. This function hangs on my pc. If I try the same code on another PC (both XP) the same code works fine
I've tried to hard code the processName but then it will hang on the next line
myProcesses = Diagnostics.Process.GetProcessesByName(procName
(See code below
Does anyone know what may be the cause and how to solve this problem
Imports System.Runtime.InteropService
Public Class Global
<DllImport("user32.dll")> Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolea
End Functio
<DllImport("User32.dll")> Private Shared Function GetWindowLong(ByVal HWND As IntPtr, ByVal Index As Integer) As Intege
End Functio
Private Const SW_RESTORE As Integer =
Private Const GWL_STYLE As Integer = -1
Private Const WS_MINIMIZE As Integer = &H2000000
Public Shared Sub Main(
Dim PrevProcessID As Integer = PrevInstance(
If PrevProcessID = -1 The
Application.Run(New Form1
Els
AppActivate(PrevProcessID
End I
End Su
Private Shared Function PrevInstance() As Intege
Dim myProcesses As Process(
Dim localProcess As Process = Diagnostics.Process.GetCurrentProces
Dim procName As String = localProcess.ProcessNam
myProcesses = Diagnostics.Process.GetProcessesByName(procName
If UBound(myProcesses) > 0 The
Dim otherProcess As Proces
If myProcesses(0).Id = Process.GetCurrentProcess.Id The
otherProcess = myProcesses(1
Els
otherProcess = myProcesses(0
End I
Dim result As Intege
result = GetWindowLong(otherProcess.MainWindowHandle, GWL_STYLE
If (result And WS_MINIMIZE) = WS_MINIMIZE The
ShowWindow(otherProcess.MainWindowHandle, SW_RESTORE
End I
Return otherProcess.I
Els
Return -
End I
End Functio
End Class