c# - Hanging when process WaitForExit in for loop -
i creating gui application using visual c# 2010 (.net framework 3.5). how change code no stops responding?
for (int = listbox1.items.count - 1; >= 0; i--) { listbox1.selectedindex = i; process myprocess = new process(); myprocess.startinfo.filename = "ffmpeg.exe"; myprocess.startinfo.workingdirectory = ""; myprocess.startinfo.arguments = " -i \"" + listbox1.selecteditem + "\" " + "-y "; myprocess.startinfo.createnowindow = true; myprocess.startinfo.windowstyle = processwindowstyle.hidden; myprocess.start(); myprocess.waitforexit(); listbox1.items.removeat(i); }
the convert program time use converting. how show new form or messengebox running application? want respond window. history loop: how do loop through items in list box , remove item?
waitforexit
, unsurprisingly, block thread until process has exited.
alternatively, can use exited
event notified when process has exited.
you need set enableraisingevents
property true
in order exited
event fired.
myprocess.enabledraisingevents = true; myprocess.exited += new eventhandler(myprocess_exited); myprocess.start(); void myprocess_exited(object sender, eventargs e) { //process has exited, implement logic here listbox1.items.remove... }
Comments
Post a Comment