.net - How to avoid standard input getting stuck in c# process -
.net - How to avoid standard input getting stuck in c# process -
i'm writing programme check whether submit code right or not. here of code...
process submitprog; streamwriter proginput; string input;//it submitprog's standard input //initialization //... submitprog.start(); proginput = submitprog.standardinput; proginput.write("{0}",input); proginput.close(); proginput.dispose(); while(!submitprog.hasexited) if(timeout) submitprog.kill();
amazingly stuck @ line proginput.write("{0}",input);
while input big plenty , submit programme didn't read anything.
some submit code might tricky while(1);
doing nothing. can kill process when input file little enough. on contrary, if input file bigger, programme won't check timeout , stuck while reading input.
do have solution avoid getting stuck in code doesn't read anything. thanks.
you're @ mercy of size of standard input buffer , programme you're testing. if doesn't read buffer, write standard input can block.
one way avoid issue write standard input stream on different thread, eg threadpool thread. place write, close, dispose lines in threadpool task , utilize threadpool.queueuserworkitem.
as side note, probable don't need phone call proginput.close , proginput.dispose. dispose phone call should fine.
c# .net process
Comments
Post a Comment