VB.NET Wait a DOS shell program to terminate before continuing- doesn't work -
i building windows forms application on vs2010, through need execute 3d party dos shell program (opensees.exe), open source file in , perform analysis. after this, output files created need read again in vb.net app. thing analysis in opensees may take long time, vb code has wait before carrying on.
for this, have tried both "shellandwait" sub along "waitforsingleobject" function , "process class" option, neither of works. dos shell program initializes, closes immediately, not letting analysis complete , required output created.
here code snippets used: 1st try: shellandwait
private declare function openprocess lib "kernel32" (byval dwdesiredaccess _ long, byval binherithandle long, byval dwprocessid long) long private declare function waitforsingleobject lib "kernel32" (byval hhandle _ long, byval dwmilliseconds long) long private declare function closehandle lib "kernel32" (byval hobject long) long private sub shellandwait(byval program_name string, _ optional byval window_style appwinstyle = vbnormalfocus, _ optional byval max_wait_seconds long = 0) dim lngprocessid long dim lngprocesshandle long dim datstarttime date const wait_timeout = &h102 const synchronize long = &h100000 const infinite long = &hffffffff ' start program. on error goto shellerror lngprocessid = shell(program_name, window_style) on error goto 0 threading.thread.sleep(1500) 'system.windows.forms.application.doevents() sendkeys.send("source " & filename & ".tcl") sendkeys.send("{enter}") ' wait program finish. ' process handle. lngprocesshandle = openprocess(synchronize, 0, lngprocessid) if lngprocesshandle <> 0 datstarttime = if waitforsingleobject(lngprocesshandle, 250) <> wait_timeout exit end if 'doevents() if max_wait_seconds > 0 if datediff("s", datstarttime, now) > max_wait_seconds exit end if loop closehandle(lngprocesshandle) end if exit sub shellerror: end sub ... shellandwait("opensees.exe", , 3)
2nd try: processstart
dim p new process dim psi new processstartinfo("opensees.exe", "source " & filename & ".tcl") p.startinfo = psi p.start() p.waitforexit()
i don't understand why isn't working. appreciated!
try this:
shell("opensees.exe <arguments>",, true)
Comments
Post a Comment