473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help w/ Single Instance

wg
I am attempting to prevent a second instance of my application from
starting. I have the following code at the beginning of Form_Load
If Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName).Length
1 Then

Me.Close()
Application.Exit()
Logger.LogMessage("FormLoad", "Second instance of application attempted")
End If
I know that it is going into the If-Then condition because it writes to my
logger. But the 2nd application still starts up. Should I set the startup to
Sub Main? Or can anyone offer suggestions?

Thanks

wg
Nov 21 '05 #1
3 879
WG,

See this sample on our website.

http://www.windowsformsdatagridhelp....6-343ac05a7617

I hope this helps,

Cor
Nov 21 '05 #2
"wg" <wg@hotmail.com> schrieb:
I am attempting to prevent a second instance of my application from
starting. I have the following code at the beginning of Form_Load
If
Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName).Length
1 Then

Me.Close()
Application.Exit()
Logger.LogMessage("FormLoad", "Second instance of application attempted")
End If
I know that it is going into the If-Then condition because it writes to my
logger. But the 2nd application still starts up. Should I set the startup
to Sub Main? Or can anyone offer suggestions?


I suggest to put the code in the 'Sub Main' instead of the form, because it
doesn't make much sense to load the form if it should not be shown.
Additionally it's not guaranteed that the 'ProcessName' is unique for your
application, especially if you are using a simple name like "Calculator".
Using a mutex will help to avoid this problem:

<URL:http://www.yoda.arachsys.com/csharp/faq/#one.application.instance>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
wg
Thanks for the help, this worked great.
wg
"wg" <wg@hotmail.com> wrote in message
news:Qz*******************@bignews5.bellsouth.net. ..
I am attempting to prevent a second instance of my application from
starting. I have the following code at the beginning of Form_Load
If
Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName).Length
1 Then

Me.Close()
Application.Exit()
Logger.LogMessage("FormLoad", "Second instance of application attempted")
End If
I know that it is going into the If-Then condition because it writes to my
logger. But the 2nd application still starts up. Should I set the startup
to Sub Main? Or can anyone offer suggestions?

Thanks

wg

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Ho | last post by:
Hi Everyone, I have this code of Mersenne twister, which produces the random numbers, one of the fastest codes as far as I know to produce random numbers. Anyways, it's writen in c# and I need to...
16
by: Basil Fawlty | last post by:
Hi everyone, I have an assignment, to create a simple VB program that computes the volume of a cylinder. The Form is pretty simple, it has a label and text box for base radius, another for height...
9
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to...
2
by: cpressley2 | last post by:
Hi, On a multi-partition instance, can you create a database on a single parition? How??? The db architects want to use one instance for four databases where only one is big enough for a...
3
by: sklett | last post by:
I suspect the answer might be in one of the words of my subject, but here goes anyway. I'm working on a system that will execute a very long (300+) chain of task objects. Here is some quick...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.