.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How run one instance of .exe file in my machine....

Posted By: susant     Posted Date: December 30, 2008    Points:2   Category :C#
I want to open only one instance of an application (.exe) in my Machine, what should i do?

C# + Windows application...

what will be the code?? or which properties i have to set??

Responses
Author: Rahul             
Posted Date: December 30, 2008     Points: 5   

Hi,
You can use mutex concept to check the instance of the application running or not. Just modyfy the Main Method of the form like this and see


[STAThread]
static void Main()
{
bool checkApps;

Mutex mutex = new System.Threading.Mutex(true, "YourApplicationName", out checkApps);
if (!checkApps)
{
MessageBox.Show("Application is already running.");
return;
}

Application.Run(new Form1());
GC.KeepAlive(m);
}



Author: susant             
Posted Date: December 30, 2008     Points: 5   

Hi rahul

u can in this way...

[STAThread]
static void Main()
{

Process aProcess = Process.GetCurrentProcess();
string aProcName = aProcess.ProcessName;
if (Process.GetProcessesByName(aProcName).Length > 1)
{

Application.ExitThread();
}
else
{
Application.Run(new EaseInventory.Interfaces.frmLogOn());

}
}

But how to Activate my current running process bcz my application is in minimize mode in system tray.. so how to make it maxiize when the user again click on shortcut...?

Author: Rahul             
Posted Date: December 30, 2008     Points: 5   

Hi try this link to restore windows application

http://www.c-sharpcorner.com/UploadFile/mrmohankumar/MinorMaxwindow01312008054718AM/MinorMaxwindow.aspx



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend