Click here to Skip to main content
13,355,726 members (84,415 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 12 Feb 2013

Calling a console application from the web on button click event

, 12 Feb 2013
Rate this:
Please Sign up or sign in to vote.
How to call a console application from the web on button click.


I am sharing here the code to call a console application from a web on a button click event. We can track the begin and end time of the application here. The most important thing is we can also check whether the process is already running priorly or not.

The code snippet is as follows:

protected void btnStartProcess_Click(object sender, EventArgs e)
    // We can configure the path from the web config file too

    string filePath = @"C:\\Users\\arnav\\Desktop\\Phrase value Util\\abc.exe";   

    System.Diagnostics.ProcessStartInfo info = 
      new System.Diagnostics.ProcessStartInfo(filePath, "");

    //System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = info;
    //while (p.Responding)
    while (!IsProcessOpen("abc"))
    //Here we can check for the application is running priorly or not
        //This line gets the start time of the process
        string startTime = p.StartTime.ToString();

    string endTime = p.ExitTime.ToString();
    //This line gets the end time of the process


public bool IsProcessOpen(string name)
    //here we're going to get a list of all running processes on
    foreach (Process clsProcess in Process.GetProcesses())
        if (clsProcess.ProcessName.Contains(name))
            return true;
    return false;

Here we can check the process is priorly open or not from web itself. This will help us in finding a single application running instances. It prevents the multiple instances at server.

In this way we can call a console application from a web application using a button click event. Hopw this will be helpfull to all.


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


About the Author

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
sisirp8813-Feb-13 4:01
membersisirp8813-Feb-13 4:01 
Question[My vote of 2] Logic flaws Pin
John Brett13-Feb-13 0:42
memberJohn Brett13-Feb-13 0:42 
AnswerRe: [My vote of 2] Logic flaws Pin
arnavs13-Feb-13 2:39
memberarnavs13-Feb-13 2:39 
AnswerRe: [My vote of 2] Logic flaws Pin
Member 245269817-Sep-14 2:45
memberMember 245269817-Sep-14 2:45 
GeneralRe: [My vote of 2] Logic flaws Pin
John Brett17-Sep-14 5:50
memberJohn Brett17-Sep-14 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 12 Feb 2013
Article Copyright 2013 by arnavs
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid