|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article describes a component that makes a Winform application single instance. Background'Why another Single Instance implementation', some of you might ask. Well the short answer is that I started out with the implementation from Michael Potter but ran into problems when I tried to use it with an application that was minimized to the explorer status area. The solution presented here uses a Mutex to detect an already running instance and remoting to signal the starting of a new instance. Using the codeTo use the component, is has to be added to the toolbox first. The component can then be dropped onto a form where it will show up in the component tray. The image below shows the properties (events) for a
For some applications, it may be useful to install an private void singleInstance1_InstanceActivate(object sender,
rr.Windows.Forms.SingleInstance.InstanceActivateEventArgs e)
{
foreach (string s in e.CommandLineArgs)
{
Debug.WriteLine(s);
}
}
The default behavior of the component after e.Cancel=true; Points of interestWhile testing the component on XP with a different user account, while one instance of the test application was already running under my normal account, I started getting a TcpChannel chan = new TcpChannel(0);
But now the problem was that the client could not connect to the server because, it didn't know the port number the server was listening on. After considering several different approaches I finally decided to use a registry key in the Another implementation detail that makes me a bit uneasy is that I use, Process.GetCurrentProcess().Kill();
in the middle of the form's History
|
|||||||||||||||||||||||||||||||||||||||||||