c# - How to get the process Id safely after process.Start()? -
when program copied many locations , started independently, error may appear:
processstartinfo startinfo = new processstartinfo(exepath); startinfo.windowstyle = processwindowstyle.hidden; startinfo.errordialog = false; process process = new process() { startinfo = startinfo }; bool isstarted = process.start(); int processid = process.id; // failed bellow when isstarted false system.invalidoperationexception: no process associated object.
since starting exe files don't need useshellexecute feature. unfathomable reason useshellexecute set true default. using entails lot of complexity.
set useshellexecute false , start should return true. then, id should valid. sure dispose of process instance.
Comments
Post a Comment