{"id":4870,"date":"2014-03-30T16:11:23","date_gmt":"2014-03-30T16:11:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-process-instance-standardoutput-invalidoperationexception-cannot-mix-synchronous-and-asynchronous-operation-on-process-stream-collection-of-common-programming-errors\/"},"modified":"2014-03-30T16:11:23","modified_gmt":"2014-03-30T16:11:23","slug":"c-process-instance-standardoutput-invalidoperationexception-cannot-mix-synchronous-and-asynchronous-operation-on-process-stream-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/c-process-instance-standardoutput-invalidoperationexception-cannot-mix-synchronous-and-asynchronous-operation-on-process-stream-collection-of-common-programming-errors\/","title":{"rendered":"C# Process &lt;instance&gt;.StandardOutput InvalidOperationException &ldquo;Cannot mix synchronous and asynchronous operation on process stream.&rdquo;-Collection of common programming errors"},"content":{"rendered":"<p>I tried this<\/p>\n<pre><code>        myProcess = new Process();\n\n        myProcess.StartInfo.CreateNoWindow = true;\n        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;\n\n        myProcess.StartInfo.FileName = \"Hello.exe\";\n\n        myProcess.StartInfo.Arguments =\"-say Hello\";\n        myProcess.StartInfo.UseShellExecute = false;  \n\n        myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);\n        myProcess.ErrorDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);\n        myProcess.Exited += new EventHandler(myProcess_Exited);\n        myProcess.EnableRaisingEvents = true;\n\n        myProcess.StartInfo.RedirectStandardOutput = true;\n        myProcess.StartInfo.RedirectStandardError = true;\n        myProcess.StartInfo.ErrorDialog = true;\n        myProcess.StartInfo.WorkingDirectory = \"D:\\\\Program Files\\\\Hello\";\n\n        myProcess.Start();\n\n        myProcess.BeginOutputReadLine();\n        myProcess.BeginErrorReadLine();\n<\/code><\/pre>\n<p>Then I am getting this error.. <img decoding=\"async\" src=\"http:\/\/img188.imageshack.us\/img188\/3759\/errorstack.jpg\" \/><\/p>\n<p>My process takes very long to complete, so I need to show progress in runtime.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I tried this myProcess = new Process(); myProcess.StartInfo.CreateNoWindow = true; myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; myProcess.StartInfo.FileName = &#8220;Hello.exe&#8221;; myProcess.StartInfo.Arguments =&#8221;-say Hello&#8221;; myProcess.StartInfo.UseShellExecute = false; myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived); myProcess.ErrorDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived); myProcess.Exited += new EventHandler(myProcess_Exited); myProcess.EnableRaisingEvents = true; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.RedirectStandardError = true; myProcess.StartInfo.ErrorDialog = true; myProcess.StartInfo.WorkingDirectory = &#8220;D:\\\\Program Files\\\\Hello&#8221;; myProcess.Start(); myProcess.BeginOutputReadLine(); myProcess.BeginErrorReadLine(); Then I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4870","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4870"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4870\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}