﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum / General .NET Discussion / .NET Forums  / Single Instance Application... / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>forum@strataframe.net</webMaster><lastBuildDate>Thu, 08 Jan 2009 11:40:00 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>Hi Larry.&lt;/P&gt;&lt;P&gt;Thanks for the code snippet. I was just trying to accomplish this, and it worked really fine.&lt;/P&gt;&lt;P&gt;:smooooth:</description><pubDate>Mon, 10 Dec 2007 12:24:30 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>Haha, yep, Larry, much simpler.  Good idea.</description><pubDate>Mon, 10 Dec 2007 08:40:56 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>RE: Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>Robin,&lt;/P&gt;&lt;P&gt;I've been using the mutex method for restricting an application to a single instance. It's easy to implement and so far it's worked well for me. By varying the safeName you should be able to over come the problem in Terminal Services.&lt;/P&gt;&lt;P&gt; I include the following code at the top of Public Shared Sub Main in AppMain.&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; firstInstance &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Boolean&lt;/FONT&gt;&lt;FONT size=2&gt; = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;False&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'-- Create a name based on the user application path. &lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; safeName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt; = Application.UserAppDataPath.Replace(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"\"&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"_"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; myMutex &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Mutex = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; Mutex(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;True&lt;/FONT&gt;&lt;FONT size=2&gt;, safeName, firstInstance)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'-- Bail if not first instance.&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Not&lt;/FONT&gt;&lt;FONT size=2&gt; (firstInstance) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Exit&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'-- Make sure the program holds the mutex as long as it is running.&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;GC.KeepAlive(myMutex)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;See &lt;A href="http://www.ai.uga.edu/mc/SingleInstance.html"&gt;http://www.ai.uga.edu/mc/SingleInstance.html&lt;/A&gt; for more info. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;-Larry&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Fri, 07 Dec 2007 10:33:07 GMT</pubDate><dc:creator>Larry Caylor</dc:creator></item><item><title>RE: Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>Thanks Ben. I'll start looking through that for a good starting point at least.&lt;/P&gt;&lt;P&gt;Robin Giltner</description><pubDate>Fri, 07 Dec 2007 10:30:44 GMT</pubDate><dc:creator>Robin J Giltner</dc:creator></item><item><title>RE: Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>It's complicated, but not impossible.  You might want to duplicate what .NET does with the IsSingleInstance property of the Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class.  I opened the Microsoft.VisualBasic.dll with Reflector and looked at the Run() method.  The first thing it checks on is the IsSingleInstance property.  If it's a single instance, then it checks the application instance ID through some stuff and makes sure there's not already one running in memory.  So, it would be pretty simple to just copy the code out of Reflector and add it to your application.</description><pubDate>Fri, 07 Dec 2007 09:01:17 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>Single Instance Application...</title><link>http://forum.strataframe.net/Topic12923-14-1.aspx</link><description>When using Strataframe the required Startup Object is AppMain to that the database connections for the Business Objects can be established, and with that, you can't use the Visual Studio Option of Single Instance Application in the Application Properties.  So I was wondering what was the best way of handling this manually.&lt;/P&gt;&lt;P&gt;I spent a few minutes reading through some ways people have done this online, but it seems to boil down to searching through the processes and finding one that matches your form's Title or something such.  I ended writing a quick method that searches on the type of the form in the AppMain's InitApplication method.&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Is this the best way to handle this ?  Also this doesn't currently allow the same application to be run by multiple users on the same system, ie users over Terminal Services etc.  I guess I would have to add another quick check for if the Owner of that Process is the current Application's process owner or some such.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;I was just wanting to get some input from anyone who may have had to do this as well.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Thanks&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Robin Giltner&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Thu, 06 Dec 2007 13:25:35 GMT</pubDate><dc:creator>Robin J Giltner</dc:creator></item></channel></rss>