工艺状态显示 [英] process status display

查看:117
本文介绍了工艺状态显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试开发基于表单的应用程序.通过单击一个菜单项,我有了homeform,它将打开另一个窗口.在该窗口中,最后一步是编译cpp文件,并通过关闭当前窗口来在homeform上并行地向用户显示编译状态.

我正在将一组cpp源文件收集到一个列表中,并多次使用以下代码(基于文件数)进行编译.



i am trying to develop form based appl. in that i have homeform by clicking on one menu item it will open another window . in that window the last step is compilation of cpp files and paralelly display status of compilation to user on homeform by closing the current window.

i am collecting set of cpp sourcefiles to a list and using following code multiple times(based on number of files)for compile.

public void ExecuteCommandSync(string command)
        {
           // create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
                // Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
                System.Diagnostics.ProcessStartInfo procStartInfo = new
                 System.Diagnostics.ProcessStartInfo("cmd", "/c" + command);
                // The following commands are needed to redirect the standard output. 
                procStartInfo.RedirectStandardOutput = true;
                procStartInfo.RedirectStandardError = true;
                procStartInfo.UseShellExecute = false;
               // Now we create a process, assign its ProcessStartInfo and start it
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();
                // Get the output into a string
                string result = proc.StandardOutput.ReadToEnd();
                string error = proc.StandardError.ReadToEnd();
                                                            
            }



我们正在尝试将上述代码中的错误"和结果"字符串写到list< string>中.并尝试在homeform上显示.但是当我们关闭当前窗口时,该列表< string>没有重定向到主页.并且我无法达到并行性(将编译和状态显示到主页).

上面的函数将被多次调用(基于选择用于编译的cpp文件的数量).



we are trying to write "error" and "result" strings in above code to a list<string> and trying to display on homeform . but when we close current window that list<string> is not redirecting to homepage.and i am unable to achive parallelism (compiling and status display to homepage).

above function will be called for multiple times (based on number of cpp files selected for compilation).

推荐答案

不仅这实质上是一个重新发布(请参阅我的评论问题),但您显然忽略了我过去的回答重定向过程状态 [ ^ ].

我是否解释过,您不需要使用"/c"运行"cmd"?您不需要它.即使在上面显示的上一个答案中,我也必须重复多次相同的操作.不是,您使用的是两个重定向流,这很好.

现在,什么是不重定向到首页"?什么是首页"?这个词看起来完全无关紧要.

您无需检查项目状态.但是,您可以.您只需要在这里: http://msdn.microsoft.com/zh-CN/library/system.diagnostics.process.aspx [ ^ ].
您真正需要的是与您生成的过程进行同步.您需要进行阻塞调用,这将使您的线程进入睡眠状态,直到子进程终止.为此,请呼叫System.Diagnostics.Process.WaitForExit().就这样.

而且,当然总是都在单独的线程中执行所有操作.请参阅本节第一段中我以前的答案参考.

—SA
Not only this is essentially a re-post (please see my comment to the question), but you apparently ignored my past answer redirection of processstatus[^].

Did I explain that you don''t need to run "cmd" with "/c"? You don''t need it. Even in my previous answer shown above I had to repeat same things more than once. Not you are using two redirected streams, which is good.

Now, what is "is not redirecting to homepage"? what''s "homepage"? This term looks completely irrelevant.

You don''t need to check the project status. However, you can. All you need is here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].
What you really need is synchronization with the process you''ve spawned. You need to make a blocking call which would put your thread to sleep until the child process terminates. For this purpose, call System.Diagnostics.Process.WaitForExit(). That''s it.

And, of course, always execute it all in a separate thread. See my previous answer references in first paragraph of this one.

—SA


这篇关于工艺状态显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆