Hi there!
I am a newbie of .NET and I need help to avoid opening the same application twice at the same time in VB.Net. Thanks for all your help.
Monkiller
9 3247
Hi Monkiller!
I have moved your question to the .NET forum. The .NET Articles section is reserved for articles that are purely informational; like "how-tos" etc. The .NET Forum is the place for your questions. In the future please post your questions here (Blue Menu Along the Top: Forums->.NET).
You should get more help here.
Cheers!
-Frinny
You might use some code like the following - -
Private Function IsRunning() As Boolean
-
Dim CurrentProcess As Process = Process.GetCurrentProcess
-
For Each p As Process In Process.GetProcessesByName(CurrentProcess.ProcessName)
-
If (p.Id <> CurrentProcess.Id) Then
-
If p.MainModule.FileName.ToLower.Equals(CurrentProcess.MainModule.FileName.ToLower) Then
-
Return true
-
End If
-
End If
-
Next
-
Return false
-
End Function
-
...and call that function from your constructor before you initialize your components?
Probably not the most efficient route for what you're seeking to accomplish, but it should function :-)
Thank you guys so much, I will try to see!
have a good day!
You might use some code like the following - -
Private Function IsRunning() As Boolean
-
Dim CurrentProcess As Process = Process.GetCurrentProcess
-
For Each p As Process In Process.GetProcessesByName(CurrentProcess.ProcessName)
-
If (p.Id <> CurrentProcess.Id) Then
-
If p.MainModule.FileName.ToLower.Equals(CurrentProcess.MainModule.FileName.ToLower) Then
-
Return true
-
End If
-
End If
-
Next
-
Return false
-
End Function
-
...and call that function from your constructor before you initialize your components?
Probably not the most efficient route for what you're seeking to accomplish, but it should function :-)
Hi seligerasmus, it works great, thanks alot. but I have one more problem now and trying to solve so can you look at this when you have time and give me some advise? I want to show the current process if it is running. Thanks
Hi Monkiller!
I have moved your question to the .NET forum. The .NET Articles section is reserved for articles that are purely informational; like "how-tos" etc. The .NET Forum is the place for your questions. In the future please post your questions here (Blue Menu Along the Top: Forums->.NET).
You should get more help here.
Cheers!
-Frinny
OK, thats fine. I'll follow your instruction. Thanks
Hi there!
I am a newbie of .NET and I need help to avoid opening the same application twice at the same time in VB.Net. Thanks for all your help.
Monkiller
Hi!
For dealing with this kind of problems there is a class called Mutex, here is an example: - static void Main()
-
{
-
s_mutex = new Mutex(true,Assembly.GetExecutingAssembly().GetName().Name);
-
-
if (s_mutex.WaitOne(0, false))
-
{
-
Application.Run(new WinForm());
-
}
-
else
-
MessageBox.Show("already an instance of app running!","Attention");
-
-
-
-
-
}
Hi seligerasmus, it works great, thanks alot. but I have one more problem now and trying to solve so can you look at this when you have time and give me some advise? I want to show the current process if it is running. Thanks
Greetings, Monkiller.
I'm glad that it worked for you. I'm a little confused about your question - Do you want to show the active form when it's not running? Or do you mean you wish to display the process ID / process name? Or something else entirely?
My apologies if I'm misunderstanding the scenario. When you have an opportunity, if you could post a clarification it would be most appreciated.
Thanks,
SeligErasmus
I would guess that what he's looking for is that if he trys to run his program when it's already running, it will show the one currently running.
I am pretty sure that the Process object has something like "Show main window" or something...if not you can do a DLLIMPORT and do something like that.
Do a search for that kinda thing and you should find some info about it.
monkiller,
If you wish to bring the window of the application already running to focus, you might try this modified bit of code - -
Private Declare Function SetForegroundWindow Lib "user32.dll" Alias "SetForegroundWindow" (ByVal hWnd As IntPtr) As IntPtr
-
-
Private Function IsRunning() As Boolean
-
Dim CurrentProcess As Process = Process.GetCurrentProcess
-
For Each p As Process In Process.GetProcessesByName(CurrentProcess.ProcessN ame)
-
If (p.Id <> CurrentProcess.Id) Then
-
If p.MainModule.FileName.ToLower.Equals(CurrentProces s.MainModule.FileName.ToLower) Then
-
SetForegroundWindow(p.MainWindowHandle)
-
Return true
-
End If
-
End If
-
Next
-
Return false
-
End Function
-
aannnnnd here's the documentation for the legacy function being used.
Hope that helps.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Carlos Andr?s |
last post by:
Hi everybody.
I've got a problem. I'd like to avoid opening a new window when you
have pressed the shift key and you click in the left button of the
mouse. I've tried the next solution, in the...
|
by: D. Alvarado |
last post by:
Hello,
I am trying to open a window containing an image and I would like
the image to be flush against the window -- i.e. have no padding or
border. Can I make this happen with a single call to a...
|
by: helpSeekar |
last post by:
My application sends out alerts with multiple hyperlinks in it.
Each time user clicks on a link, it opens up a new window in case of yahoo,
hotmail email clients. In case of lotus notes email...
|
by: srik |
last post by:
Dear All,
I created a simple ASP.net web application on my desktop system, which
has Windows XP as the Operating system.
I then moved the ASP.net application to my server which has Windows...
|
by: Peter Rilling |
last post by:
I have an interesting issues that, although I not blocking me, is not very
performance. Maybe someone can suggest a better way of doing this.
1) I have a page that displays a grid with command...
|
by: Lasse Eskildsen |
last post by:
Hi,
How can I make sure I don't show the same form twice? If the form is already
shown, just focus. I tried using ownedforms, but can't quite make it work...
Thanks in advance!
--
Lasse
|
by: amit.atray |
last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc)
having some Old C-Code (ansi + KR Style) and code inspection shows
some big size variable (auto) allocated (on stack)
say for ex.
char...
|
by: trooper |
last post by:
I have a situation where an application is present in the form of one
dll. The interface to the application is an api. The code update some
global data structures. This dll comes as third party...
|
by: Phil Stanton |
last post by:
I have a form with a button which is supposed to open an Excel file (With
lots of Macros /VBA) in it. The Excel file gets it's data from the Access
program
Here is the code
Private Sub...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |