Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

limit applications to one instance in Visual C++ .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alper AKCAYOZ - 15 Jun 2005 15:18 GMT
Hello,
I have developped an application used by Windows Forms (.NET) at Visual C++
.NET v2003. I would like to limit my application to one instance working at a
moment. More than one working application is not allowed. I am requesting
help about this question.
I found 2 article at KnowledgeBase, which are Article ID : 243953 (How to
limit 32-bit applications to one instance in Visual C++) and Article ID :
238100 - (How to limit 32-Bit MFC SDI applications to a single instance on
WinCE). Unfortunately, these two articles are not fitted for my purpose and
required because of Windows Forms (.NET).

Thank you very much in advance.
Signature

~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)

Ronald Laeremans [MSFT] - 15 Jun 2005 20:34 GMT
> Hello,
> I have developped an application used by Windows Forms (.NET) at Visual C++
[quoted text clipped - 8 lines]
>
> Thank you very much in advance.

The cannonical way is to create a named mutex or other named system
object in the startup code and check for a pr-existing one and exit if
there is one.

Ronald Laeremans
Visual C++ team
Alper AKCAYOZ - 16 Jun 2005 17:07 GMT
Hello,
I created a new Windows Forms .NET project. Then into the Form1 class in
Form1.H , I defined a public-signatured static Mutex object as below:
 ....
 public __gc class Form1 : public System::Windows::Forms::Form
{
  public: static System::Threading::Mutex *mt = NULL;
   ...
 }

Then, into the main function of application that starts the program, I coded
blow statements:

#include "stdafx.h"
#include "Form1.h"
using namespace RunOnlyOnceAtATime;

[System::STAThreadAttribute]
void __stdcall _tWinMain()
{   
 Form1::mt = new System::Threading::Mutex(false, "myMutex");
 if (!Form1::mt->WaitOne(10, true))
 {
     // Another copy of program is running
     MessageBox::Show(S"Program is already running.", S"Working Program");
     return;
  }
  else
  {
      //Run application.
      Form1::mt->WaitOne();//Yalnızca bu çalışıyor mutexi kilitliyelim
      Application::Run(new Form1());
   }
}

Above codes solved my problem. Thank you very much.
Signature

~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)

> > Hello,
> > I have developped an application used by Windows Forms (.NET) at Visual C++
[quoted text clipped - 15 lines]
> Ronald Laeremans
> Visual C++ team

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.