StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Single Instance Application...Expand / Collapse
Author
Message
Posted 12/06/2007 1:25:35 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2008 10:01:54 AM
Posts: 105, Visits: 650
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.

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.

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.

I was just wanting to get some input from anyone who may have had to do this as well.

Thanks

Robin Giltner

Post #12923
Posted 12/07/2007 9:01:17 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 10/21/2008 9:20:58 AM
Posts: 2,685, Visits: 1,887
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.


www.bungie.net
Post #12931
Posted 12/07/2007 10:30:44 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2008 10:01:54 AM
Posts: 105, Visits: 650
Thanks Ben. I'll start looking through that for a good starting point at least.

Robin Giltner

Post #12936
Posted 12/07/2007 10:33:07 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 11/17/2008 10:50:47 AM
Posts: 368, Visits: 1,850
Robin,

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.

 I include the following code at the top of Public Shared Sub Main in AppMain.

Dim firstInstance As Boolean = False
'-- Create a name based on the user application path.
Dim safeName As String = Application.UserAppDataPath.Replace("\", "_")
Dim myMutex As Mutex = New Mutex(True, safeName, firstInstance)
'-- Bail if not first instance.
If Not (firstInstance) Then Exit Sub
'-- Make sure the program holds the mutex as long as it is running.
GC.KeepAlive(myMutex)


See http://www.ai.uga.edu/mc/SingleInstance.html for more info.

-Larry

Post #12937
Posted 12/10/2007 8:40:56 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 10/21/2008 9:20:58 AM
Posts: 2,685, Visits: 1,887
Haha, yep, Larry, much simpler.  Good idea.


www.bungie.net
Post #12949
Posted 12/10/2007 12:24:30 PM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Today @ 10:41:04 AM
Posts: 793, Visits: 11,573
Hi Larry.

Thanks for the code snippet. I was just trying to accomplish this, and it worked really fine.

Post #12960
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 10:54am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.094. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.