c# - Tracking multiple processes at same time -
have application (winforms) downloads file user's temporary folder, opens file user see contents, , when file closed, file gets deleted temp folder. application working ok if open let's 1 .pdf , 1 .doc problem appears when trying open 1 .doc if winword process still runing (doesn't matter if opened app or directly user).
i'm using following code:
_openfileproces = system.diagnostics.process.start(tempfilename); _openfileproces.enableraisingevents = true; _openfileproces.exited += new eventhandler(_openfileproces_exited);
and 1 clear temp
void _openfileproces_exited(object sender, eventargs e) { string s = ((system.diagnostics.process)sender).startinfo.filename; system.io.file.delete(s); }
it seems running process stopping own.. , due stopping delete file or generate error while trying delete file.
have suggestion how can open own process? thing not know file type have open (it anything) , i'm counting on windows choose best application. test, notepad works ok, winword , acrobat closes process.
thank you
i suspect microsoft word doing same thing here raymond chen describes windows shell doing here:
a customer wanted monitoring lifetime of explorer window.
"we want launch copy of explorer open specific folder, wait until user closes folder before continuing. tried launching copy of explorer folder on command line, doing waitforsingleobject on process handle, wait completes without waiting. how wait until user closes explorer window?"
this case of solving problem halfway , having trouble other half.
the reason
waitforsingleobject
returns explorer single-instance program (well, limited-instance). when open explorer window, request handed off running copy of explorer, , copy of explorer launched exits. that's whywaitforsingleobject
returns immediately.
in case, word running, when create second word process , instruct open document, hands request off instance of word running, , quits second process launched immediately.
that's you're seeing when describe "the running process stopping own". because second instance gets closed after launch it, exited
event raised , code tells delete file!
you astutely observe notepad (unlike word , adobe acrobat) works fine. that's because notepad designed multiple-instance application. can open many copies of notepad want; doesn't care if there's 1 or 6 copies open on desktop. , more importantly, asking shell open text document in notepad opens second copy of notepad application, rather sending request first instance open new window new doc.
Comments
Post a Comment