none
System.Diagnotig.Process.Start() return values RRS feed

  • General discussion

  • Hi

    Spending already some time to get understanding what really means if System.Diagnotig.Process.Start() return return false?

    I am aware what documentation of this method says like this.

    "true if a process resource is started; false if no new process resource is started (for example, if an existing process is reused). "

    and this

    "Use this overload to start a process resource and associate it with the current Process component. The return value true indicates that a new process resource was started. If the process resource specified by the FileName member of the StartInfo property is already running on the computer, no additional process resource is started. Instead, the running process resource is reused and false is returned. "

    In my case only parameters of StartInfo what I set are FileName (=some exe file), Arguments and WindowStyle (=ProcessWindowsStyle.Normal) before call Start() method.

    In 99% of case it return true and everythings works ok. Anyway for some reason sometimes it return false. I really not sure is that a error or what and is my process (exe) really strated or not. Currently my implementation think that this is a error and tell user that process is not started it really looks so but I am not 100% sure.

    I also notice that when it start returning false I need to reboot machine to get that return value true again, nothing else do not seems to help.

    How it is?

    Thanks in advance!

    Monday, November 23, 2015 7:21 PM

All replies

  • It simply means the exe that you are trying to start now has already started. So you always get a false as the exe is currently running. If you restart the machine, the exe has not started for the first run of your program and so you get a true.

    You can also check this by terminating the exe via the task manager. In which case you dont need a reboot of your machine.

    Tuesday, November 24, 2015 11:35 AM
  • In addition: "tasklist" on cmd will spit out all started processes and their Imagenames.

    I suggest you try to find out if the Process in question was already started by doing this before starting it:

    Process[] processes = Process.GetProcessesByName(name);

    This way you get the Process too, instead of just having it started.

    Cheers

    Edit: I'd like to propose "Sezhiyan Thiagarajan" answere as answere, but I cannot (!?)
    • Edited by MDeero Tuesday, November 24, 2015 12:44 PM
    Tuesday, November 24, 2015 12:43 PM
  • Hmm Do you mean that it is already called Start() method of same Process instance and this process is still running and now I am calling that again?

    Meaning somethig like this:

    Process pr =  new Process();

    pr.StartInfo.FileName = "Some.exe";

    pr.StartInfo.Arguments = "pla pla";

    pr.StartInfo.WindowsStyle = ProcesswindowsStyle.Normal;

    pr.Start();

    pr.Start(); // You mean that this return false because it is started already?

    That is not a case. I always make a new Process instance before set those properties and call Start() method. And I call it only once. Also Task Manager do not show any process asscociated to my exe file.

    And still it return false.

    Tuesday, November 24, 2015 4:25 PM
  • You are right, you are always making a new instance of a "Process" class. However once you start a process with an associated exe, this process would continue to run beyond your application's lifetime. Unless you explicitly kill this process.
    Wednesday, November 25, 2015 5:22 AM
  • And wait for the OS to really dispose of it. Most of these type of "errors" occur because the kill and start are called to fast after another. So you could do the Process.GetProcesses and see if it really is disposed.
    Wednesday, November 25, 2015 6:12 AM
  • Yes?

    I do not undestand how that could be a problem if another process associate to same exe is already running (in my case that it is not). Of course operating system allows to run many different processes associate to same exe!

    Wednesday, November 25, 2015 6:16 AM
  • Okay....

    The Process here is just the OS Process, not related to your exe or anything else. Its a resource on the OS. If a new one is created for the .Start(), then true is returned, if the Process was started by using an idle Process (as a resource), you get false.

    I thought you had issues with starting a Process (like an exe). But it seems you just wanted to understand what false really means.

    my bad

    It's somewhat like with Threads (except that a Thread is something completley different than a process, but that don't matter now). When you start a Thread, the Thread will (in most of the cases) not get created, instead, the Thread would be taken from the Thread Pool, which parks idle Threads (more or less). So with Processes, i don't know if there is a Pool of them, I think not, but if there is an idle (empty) Process lying around, instead of Disposing it (through hard work) and then creating a new one (as requested by .Start and wasting another huge amount of resources to create a Process, returning true), the old one is repurposed (returning false).
    • Edited by MDeero Wednesday, November 25, 2015 6:55 AM
    Wednesday, November 25, 2015 6:47 AM
  • So even if it return false my exe was started normally and I should not construe that as an error.

    Thanks


    • Edited by koltti Wednesday, November 25, 2015 7:02 AM
    Wednesday, November 25, 2015 7:02 AM
  • Please mark helpful posts and/or an answere.

    And you're welcome

    • Edited by MDeero Wednesday, November 25, 2015 7:24 AM
    Wednesday, November 25, 2015 7:23 AM
  • This was not so easy.

    I investigate that more and found that when it return false it really do not start that process (exe) at all. (not even reuse way).

    My program which try to start that process run under local system (it is windows service). When I change account to some other it start working (returning true and really strart process).

    Now it is need to find why my program is not able to start process if it run under local system and is able to start process if it run unders some other account. As I said earlier it get fixed if I reboot machine but come back is some phase again.

    Wednesday, November 25, 2015 4:08 PM
  • Then the application was build to don't run multiple times for one user, as posted earlier, try the Loop with GetProcesses("NameOf.Exe")

    Edit: forget that ^, Call WaitForExit on the process

    • Edited by MDeero Wednesday, November 25, 2015 4:16 PM
    Wednesday, November 25, 2015 4:13 PM
  • No it is not.

    There is now some limit in local system account which preventing start new processes...

    Wednesday, November 25, 2015 4:47 PM
  • SO your original problem was solved by WaitForExit?

    Please mark answer and start a new Thread (cause this seems to be something different, an error does appear somewhere else).

    For starters you could check if the application is changing permissions cause then you might need to close it not using Kill but CloseMainWindow if it has one (so it can use its Close method and clean up or similar)

    Wednesday, November 25, 2015 5:42 PM
  • Original question was that what means when Start() return false.

    No I know that when false is returned my process was not excuted. I also know that it is somehow related to user account because running (program which call Start method) under local system it return false but when I change account to somethig else it return true and process is excuted normally.

    My feeling is that some limitation is exceed and it getting failed until restart the server.

    Of course I want to know what is that limitation

    Wednesday, November 25, 2015 6:15 PM
  • So write an answere that suits your question if none was given, mark it as an answer and create a new answere with your new question

    • Edited by MDeero Wednesday, November 25, 2015 6:18 PM
    Wednesday, November 25, 2015 6:17 PM
  • Ok

    At least in my case when Start() retun false it means that process was not executed so it indicate some error and need to be check.

    I make a another thread for getting answer for reason for failure.

    Thanks all.

    Wednesday, November 25, 2015 6:32 PM
  • Please make a post that answeres your question correctly and mark it as an answere, so that everyone stumbling upon this knows whats right! And also for closing this Thread (since you'll probably won't come back to it)
    Friday, November 27, 2015 6:28 AM
  • ? This was a General dicsuccion not a Question type.

    I do not know how to do those action you ask? For exaple closing? Where that is?

    Friday, November 27, 2015 10:46 AM
  • Close = mark an answer
    Friday, November 27, 2015 10:47 AM
  • Hmm are you kidding with me or am I so stupid that I do not found place where to mark an answer. Note that this is discussion thread not a question thread.
    Monday, November 30, 2015 5:28 PM
  • Oh... didn't note that. Mhhh... dunno what to do there, normally there should be the "mark as answere" under any post, but with general discussions it might be different.
    Tuesday, December 1, 2015 7:45 AM