Windows Develop Bookmark and Share   
 index > Windows Forms General > How to identify if the Process has completed a task?
 

How to identify if the Process has completed a task?

In windows application I am creating a new process by setting

process.StartInfo.FileName = .exe;

process.StartInfo.Arguments = “some values�

Now how to identify if the process has completed this task? Since I need to kill, the process after the task is completed.

Asif Shaikh  Friday, March 07, 2008 9:10 AM

Take a look at below MSDN reference which explains different ways of getting notified of process exited.

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.exitcode(VS.80).aspx

MeetJayBlack  Friday, March 07, 2008 9:27 AM

Take a look at below MSDN reference which explains different ways of getting notified of process exited.

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.exitcode(VS.80).aspx

MeetJayBlack  Friday, March 07, 2008 9:27 AM

Thanks for your reply...

But I am not interested in knowing whether the process has been exited or not. I am interested in knowing whether the task or command provided to the process is completed or not. So that I can exit or kill the process using code.

Asif Shaikh  Friday, March 07, 2008 9:50 AM
Could you post what kind of operation you are performing on the PROCESS. For example are you doingmulti threaded operation or single thread. I just wanted to know the nature of your usage of PORCESS component before I can tell you my suggestion.
MeetJayBlack  Friday, March 07, 2008 9:57 AM

I am doing single threaded application. The process I am running is a tool where we can execute the commands. For example we can write a command to compress the file. I am invokingthis tool using C# code i.e. using Process object by passing commands as argument. Now I wanted to know whetherthese commandsare executed or not by the tool so that I can close the tool programmatically. I can use multi-Threadingif solution demands.

Asif Shaikh  Friday, March 07, 2008 10:13 AM

Hi Asif Shaikh,

Based on my understanding, you want to know how to check whether the specified Process has finished. You can use this property HasExited of your process to check whether the process has determined. You can refer to the following URL:

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.hasexited(VS.71).aspx

Hope it's helpful, if I have misunderstood you, please feel free to tell me. Thanks.

Best regards,

Roy Zhou

Roy Zhou - MSFT  Tuesday, March 11, 2008 10:01 AM

Thanks Roy Zhou,

This property indicates whether the process has terminated or not. My requirement is to know whether the task (assigned to the process) is completed or not so that I can kill the process.

E.g. If we are executing query in SQL Server it is a task while running instance of SQL Server is a process.

Asif Shaikh  Thursday, March 13, 2008 8:07 AM

You can use google to search for other answers

Custom Search

More Threads

• Zooming picture ...
• Linking a Button to another App
• combobox dropdown styles
• textbox cursor
• Save As using File Stream Object
• form's UserControl.AutoSize property keeps resetting itself to true.
• Press control-D keys will insert a date into a textbox.
• System.Net.Mail.smtpClient.send() Cannot send mail in Windows Server 2003
• Form_Load?
• Problem with AxFramerControl when display Excel documents