|
-
Jun 2nd, 2003, 01:03 PM
#1
Thread Starter
Fanatic Member
Disallow Multiple Instances of an app and focus to first instance?
I know how to only allow 1 instance (using a mutex). But I don't know how to bring focus to the original application (main form) when the user tries to open a new instance. Anyone know how?
-
Jun 2nd, 2003, 01:45 PM
#2
I don't have any code handy at the moment but I believe its AppActivate or some such.
-
Jun 2nd, 2003, 02:35 PM
#3
Frenzied Member
A while back i tried to find a way to get the Mutex owner process name or ID but i couldnt figure out how.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jun 2nd, 2003, 03:00 PM
#4
-
Jun 2nd, 2003, 03:20 PM
#5
Frenzied Member
Thanks Edneeis,
It has recommended this:
'Only works if the title of the application is the same as the ProductName.
AppActivate(Application.ProductName)
But still not a guranteed way. What is needed is the Proccess ID of the Mutex Owner.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jun 2nd, 2003, 03:23 PM
#6
Yes or the title of the application to activate, but I haven't had to deal with that yet. I so far have always known the title of the application.
-
Jun 2nd, 2003, 03:33 PM
#7
Thread Starter
Fanatic Member
My title is also always constant, so the link is exactly what I was looking for. I put the AppActivate("xxxxx") around a Try Catch just to be sure.
But I would much rather use the ProcessID as suggested. Now, on to figuring our how to get the ProcessID...
-
Jun 2nd, 2003, 03:41 PM
#8
Frenzied Member
Hey man, I didn't notice you have recommended that in that forum.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 17th, 2007, 04:07 PM
#9
Addicted Member
Re: Disallow Multiple Instances of an app and focus to first instance?
It has been a long time since you asked for this. I was just browsing and thought I would pass this along. You wanted to activate by Process ID. Since Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length returns >1, if the application is already open, you must compare the current process id to the ones found to figure out which one to activate. Hope this helps anyone.
VB Code:
Dim current As Process = Process.GetCurrentProcess()
Try
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
Try
For i As Integer = 0 To (Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length - 1)
If (Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)(i).Id) <> current.Id Then
AppActivate(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)(i).Id)
End If
Next
Catch ex As Exception
' Add code as desired
End Try
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
-
Jan 17th, 2007, 09:31 PM
#10
Frenzied Member
Re: Disallow Multiple Instances of an app and focus to first instance?
Thanks RSJIG for the suggestion. But I'm afraid the main problem which was getting the process name or ID of a mutex owner still remains. This post is about 4 years old and back to .NET FX 1.0 time. So there might be ways in newer frameworks.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|