Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an console application and i am running it using process.start() method from .aspx file using button
but the previous running console has not ye finised it job and if someone clikc again that button to start that same console application then it should throw error that same console application is already running please wait to complete it

What I have tried:

i have tried disabling the button but it is not the permanent solution
Posted
Updated 7-Oct-16 0:53am

When you start the app, keep a reference to the Process:
C#
private Process myApp = null;
...
if (myApp != null)
   {
   if (!myApp.HasExited)
      {
      throw new ApplicationException("App is still running");
      }
   }
myApp = new Process(...
 
Share this answer
 
When your app is started, create global mutex with key(like AppName) and check

C#
using System.Threading;
static void Main()
{
  bool bAppFirstInstance;
  var oMutex = new Mutex(true, @"Global\" + @"APP_NAME", out bAppFirstInstance);

  if(bAppFirstInstance)
    //Start your app
    ......
  else
   //Warn user
    ......
}
 
Share this answer
 
v2
Comments
Dave Kreskowiak 7-Oct-16 8:34am    
This does stop the process from starting at all. For a small amount time, both processes are running. The problem you have here is that the page that launched it doesn't know what the result of launching this process was. Did the process fail to do its job or not?

The real solution is to prevent the page from launching the process at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900