Process.Start
hello,
i see process.start command; way of figuring out when process ends? there callback can't find? have kick of series of processes in order, , need 1 end, next 1 begins, etc.
thanks.
here 2 methods wrote in c#.net figure out when process ends. need know process name or @ least part of process name, depending on method use. hope helps.
/// <summary> /// waits process terminate or til timeout reached /// </summary> /// <param name="sprocessname">the name of process (e.g. "notepad")</param> /// <param name="timeout">timeout in seconds</param> /// <returns>true if process terminated; /// false if process not terminated in allotted time.</returns> public bool waitforprocesstoterminate(string sprocessname, int timeout)
{
process[] processlist; datetime dstarttime = datetime.now; datetime dcurrenttime = datetime.now; timespan span = dcurrenttime.subtract(dstarttime); while (span.seconds < timeout){
processlist =
process.getprocessesbyname(sprocessname); if (processlist.length == 0){
// process terminated return true;}
thread.sleep(950);system.windows.forms.
application.doevents();dcurrenttime =
datetime.now;span = dcurrenttime.subtract(dstarttime);
system.diagnostics.
debug.print("seconds waiting = " + span.seconds);}
return false; // process not terminated}
// waitforprocesstoterminate(...)/// <summary> /// waits process terminate or til timeout reached /// </summary> /// <param name="sprocessname">the name of process (e.g. "notepad")</param> /// <param name="scaption">caption/window title</param> /// <param name="timeout">timeout in seconds</param> /// <returns>true if process terminated; /// false if process not terminated in allotted time.</returns> public bool waitforprocesstoterminate(string sprocessname, string scaption, int timeout, matchoptions match)
{
process[] processlist; datetime dstarttime = datetime.now; datetime dcurrenttime = datetime.now; timespan span = dcurrenttime.subtract(dstarttime); while (span.seconds < timeout){
processlist =
process.getprocessesbyname(sprocessname); if (processlist.length == 0){
return true; // process terminated}
else // check see if running processes have associated 'caption' title{
for (int ii = 0; ii < processlist.length; ii++){
if (processlist[ii].processname.toupper() == sprocessname.toupper()){
switch (match){
case matchoptions.exact: if (processlist[ii].mainwindowtitle.tostring() == scaption){
goto process_still_running; //break; // process still running}
break; case matchoptions.partial: if (processlist[ii].mainwindowtitle.tostring().contains(scaption)){
goto process_still_running;}
break; default: // should not happen break;}
// switch (match)}
// if processname =}
// (int ii return true; // process terminated}
// else check caption titleprocess_still_running:
thread.sleep(950);system.windows.forms.
application.doevents();dcurrenttime =
datetime.now;span = dcurrenttime.subtract(dstarttime);
system.diagnostics.
debug.print("seconds waiting = " + span.seconds);}
return false; // process not terminated}
// waitforprocesstoterminate(...)
.NET Framework > Common Language Runtime Internals and Architecture
Comments
Post a Comment