Greg Yes, this is an example where Remoting code is used, in conjunction with My and Microsoft.VisualBasic -
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic62 109.aspx Although Bill's first Visual Studio Mag article pointed to a Microsoft Connect BUG [1] which Microsoft said it would not be fixed, I'm wondering whether there is (still) some problem with the (Microsoft.VisualBasic assembly) .IsSingleInstance The bug described was for firewall and antispam/anti-virus behaviour (mainly). The problem is succinctly described as - The issue initially was based on the fact that my winforms app consumed a webservice. This was causing a problem. During testing I also figured out this behavior happens when using the Application Framework provided in .NET 2.0 for VB, and marking an application as Single Instance Application. The remoting used by the Application Framework to ensure single instance suffers from this same problem if the user clicks to deny access in the firewall when prompted. [1] Sockets.DoBind <https://connect.microsoft.com/VisualStudio/feedback/details/298407/sockets- dobind-causes-framework-to-crash-if-firewall-blocks-request> causes framework to crash if firewall blocks request I don't know how one follows up on such unfixed errors. Maybe Microsoft was saying (in 2007, prior to the release of VS2008 and whatever Framework revisions were imminent) that the problem would not be fixed for the RTM - maybe it has been subsequently. 4 years have passed. _____ Ian Thomas Victoria Park, Western Australia _____ From: [email protected] [mailto:[email protected]] On Behalf Of Greg Keogh Sent: Friday, December 30, 2011 3:24 PM To: 'ozDotNet' Subject: RE: Switching between single- and multiple-instance (WinForms) Ian, I've created a few single instance WinForms apps. In the static Main I do this skeleton code (which you've probably seen many times today): bool createdNew; appLocker = new Mutex(true, mutexName, out createdNew); if (createdNew) { LaunchApp(); // Application.Run(new Form1()) wiz generated code } else { MessageBox.Show("Already running message"); // Use a Remoting pipe to tell the original app to activate or whatever Application.Exit(); } The mutex stuff is obvious, but when I researched this several years ago I found the only reliable way of telling the original app to activate was to use a pipe Remoting channel listener. I can drag out the old code that has the two instances communicating if you need it. It sounds worse than it really is and the Remoting code was acceptably small. Greg
