| ||
|
This discussion group is now closed.
Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day. The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too. |
Hi i have written a small utility program using c# when user clicks the exe as many times the new instances of the application get created what if i want the user to limit to use only one instance application at a time.... is there any way i can achieve it in C#.. Thankyou,
New To .Net Tuesday, February 13, 2007
In terms of pure Win32 API you can use the CreateMutex Win32 API and use GetLastError to check for ERROR_ALREADY_EXISTS to detect any previous running instance.
Thankyou jussi :) I Got this ex whic works fine http://www.codeproject.com/useritems/csharponeinst.asp?df=100&forumid=270354&exp=0&select=1377873
New To .Net Tuesday, February 13, 2007
Sells' book has something on this, the relevant part of which is fortunately online: http://www.awprofessional.com/articles/article.asp?p=474650&seqNum=2&rl=1 Never done it before though.
el Wednesday, February 14, 2007
System.Threading.Mutex See Also: http://www.yoda.arachsys.com/csharp/faq/#one.application.instance Snippet: bool firstInstance; Mutex mutex = new Mutex(false, "Local\\"+someUniqueName, out firstInstance); // If firstInstance is now true, we're the first instance of the application; // otherwise another instance is running.
Richard P Wednesday, February 14, 2007
Chris, did you read it? The example is written in C#, you just add a reference to Microsoft.VisualBasic.dll, part of the .NET install.
el Friday, February 16, 2007
You're right, judging by Sells' example it looks simple enough to use this functionality from C#. The MSDN Library pages I found were talking about a VB project setting, that's why I thought it was an "exclusive" feature.
He does say he doesn't understand why the functionality wasn't added to the main framework (one of the notes, had to check in the book to find it). Although the dll is part of the distribution.
el Friday, February 16, 2007
http://www.codeproject.com/csharp/singleinstance.asp Guyyzzzzzzzzzzzzzz this is the superb example which works very fine check it out :)
New To .Net Monday, February 19, 2007
Just remember, if you use a global atom, as the code project article suggests, if the program crashes the user will not be able to restart the application until they restart the computer and clear the globla atom. But if you use a Mutex this is never a problem since windows will automatically release the mutex should the application crash. | |
Powered by FogBugz
