有关后台过程的信息 [英] information regarding background process

查看:63
本文介绍了有关后台过程的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于表单的应用程序中编译一组c ++文件,因为我有一个列表框来显示一些选定的C ++文件,并且我将它们收集在list< string>中.并将其传递给命令.

I am compiling a set of c++ files in a formbasedapplication, in that i have a listbox to display few selected C++ files and i have collected them in list<string> and passing it for command.

foreach (string file in UUT_list)
           {

               String filenamewithoutextn=Path.GetFileNameWithoutExtension(file);
               String dest=BuildFolder_path_str+"\\"+filenamewithoutextn+".o";
               String command1 = "c:\\DDC-I\\GCC\\powerpc_spe\\bin\\powerpc-eabispe-gcc.exe";
               command1 +=" " + file+" ";
               command1 += "-o " +"\""+dest+"\"";
               command1 += " " + IncludeFile_str;
               ExecuteCommandSync(command1);
           }

,并使用某些功能

ExecuteCommandSync(string command);

public void ExecuteCommandSync(string command)
{
............
............
}


因此,现在我必须在我的应用程序的主页(在一个选项卡控件中成功执行,在另一个选项卡控件中错误)上向用户显示执行信息.

请为我建议解决此问题的方法.


So now I have to display the information of execution to the user in the home page(Successful execution in one tab control and errors in another tab control) of my application.

Please suggest me solution for this problem.

推荐答案

尝试使用 ^ ]类来运行编译器并报告进度.并使用流程 [
Try to use BackgroundWorker[^] class to run the compiler and report the progress. And use Process[^] class to redirect output and error.
Be careful, BackgroundWorker runs in a different thread, you''ll be unable update the GUI objects from it (you can use Dispatcher.Invoke), but RunWorkerCompleted and ProgressChanged are fired on GUI thread.

It''s not quite simple, but it might work.

Use the BackgroundWorker to run the compiler (pass parameters, etc...). Listen for ProgressChanged
In DoWork you create a Process (the compiler process) and redirect the StandardError and StandardOutput (see documentation). Listen for ErrorDataReceived and OutputDataReceived events using lamdas. When something comes in, call worker.ReportProgress(some_number, message). You will receive the notification in BackgroundWorker.ProgressChanged on the GUI thread. Display the message in GUI.


添加到 Catalin Serafimescu 的解决方案,并在您以后的问题印象中,请此处 [ ^ ], ^ ],此处 [ ^ ]和此处 [ ^ ],我想声明多个表单也并不意味着多个线程.

表单和线程是同一事物的不同角度的视图.
通常,应用程序的所有表格都是在一个线程中创建的.它通常称为主线程或GUI线程.可以有更多的线程,但是它们都不限于与一个指定的Form交互.

而是,GUI线程与所有窗体交互,并且所有其他线程独立于其运行.那些其他线程不允许更改与UI相关的任何内容.他们必须将UI交互委派给UI线程.这就是 Control.Invoke() [ BackgroundWorker.ReportProgress [
Adding to Catalin Serafimescu''s solution and under the impression of your later questions here[^], here[^], here[^] and here[^], I''d like to state that multiple Forms do not imply multiple threads as well.

Forms and threads are views from different angles on the same thing.
Usually, all Forms of an application are created in one thread. It is often called the main thread or GUI thread. There can be more threads, but neither of them is restricted to interact with one specified Form.

Instead, the GUI thread interacts with all Forms and all other threads run independent thereof. Those other threads are not allowed to change anything UI-related. They have to delegate UI interactions to the UI thread. That''s what Control.Invoke()[^] and the already mentioned BackgroundWorker.ReportProgress[^] event are for.


这篇关于有关后台过程的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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