C # use Process to call batch processing for blocking issues,

Source: Internet
Author: User

C # use Process to call batch processing for blocking issues,
PS: I saw the familiar C # code again. I'm so happy, haha. This time I jumped into the trap and got up again. The company has its own Submit, Compile, and Publish lifecycle systems. During Compile, an external compilation program must be called to Compile the source code. Android's buddy recently changed the packaging tool from ant to gradle, so the system needs to support gradle compilation. The configuration and principles of gradle will not be discussed. You can simply google it. Write a batch processing with parameters to call gradle for compilation and packaging. Then, use process in C # For associated calls. This is a background call and requires compilation of output and error. Of course, redirection of output and error is required. (When looking for batch processing problems, you can discard redirection first so that the results can be output directly in the console)At this time, there was a very confusing problem. The batch processing of associated calls was inexplicably blocked. After the process times out and continues to be executed, the batch processing will continue.When debugging, an error message similar to overflow is displayed when the standoutput attribute is accessed when the output information is read after the timeout. As a result, google found that the batch processing was blocked only when it learned about the output redirection, which is related to this error. First, let me explain my understanding of output redirection. If process sets output redirection, an output buffer is set to write the output results of the program associated with process to the buffer. Process clears the buffer by constantly reading the content of the buffer. The buffer space is limited. If the process does not read data, the buffer will be filled at a certain time. Then, the associated process waits for the data in the buffer to be cleared, and the process waits for the end of the associated process. So,Deadlock occurred. Solution: After process is started, read the output buffer because the reading method is blocked until the associated process ends. To ensure that the main thread is not blocked, the buffer content is read asynchronously by the thread. Note: The thread must be started after the Start method and before the WaitForExit method. In addition, there are two redirection operations for output, output and error, both of which have similar problems. please ensure that the processing is complete.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.