Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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);
           }
and executing this command with some function
C#
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.
Posted
Updated 9-Jan-12 0:03am
v3

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.
 
Share this answer
 
v3
Comments
Amir Mahfoozi 9-Jan-12 7:42am    
+5 Good answer.
pasupulety 10-Jan-12 5:13am    
i am new to c# . so please let me know some briefly about solution.
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900