Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my Form Based Application i have one mainform . by clicking on toolstripmenuitem it will open one more form called "Createenvironment" form .one build button is there in this createenvironment form, clicking on this button will compile few c++ files . so now myrpoblem is when there is error in compilation of a specific file it should not continue the compilation of upcoming files in that list and createenvironment form should not close. just i want to disply error and stop compilation . please kindly suggest me.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Feb-12 0:19am    
I don't see a problem here. When you exit a method of a top-level stack frame of a thread, the thread exits. Why this is a problem?
--SA
BillWoodruff 8-Feb-12 10:27am    
Can we assume that when you say "Form based application" you mean a WinForms application.

I can't help but be curious about why someone is compiling C++ files in a second Form spawned from a ToolStripMenuItem in a first Form.

What forms of Error Handling have you researched, implemented, so far ?

Show us some code.

The answer seems so obvious that I'm thinking I'm not understanding your problem. You evidently have a form (Windows Forms?), within which you call a compiler.I would think that you would await the result of the compilation to see how the form should react - whether it's successful or resulted in an error. Can you explain a bit more clearly?
 
Share this answer
 
Comments
pasupulety 13-Feb-12 5:08am    
when we click on button that next procedure should run in seperate thread. and we should be able to stop that thread at any moment based on condition.

so in my problem i am trying to compile 10 files when we click on button.
when we click on button it should check for compiler options , building up command is another function and for running that command from c# another function. these are all functions in build.cs.

this build.cs object is created on clicking on a button and trying to compile the files . so now i need to stop that build.cs functions flow when there is an error in compilation.

1) Running a new thread when we click on button, i,e running creating build object and calling build.cs functions.
2) when there is an error in that flow that entire build.cs object should be destroyed and that compilation process should be aborted.
Okay - thank you for clarifying. I think perhaps now I see what you mean.

In general, for a problem like this I try to structure it as simply as possible. Here is what I'm envisioning, for your scenario: When you click the button that starts the build, you have a method that sets up a callback delegate or event (that the build process will use to notify you when it is done), and then spins off a distinct process to do the building (compiling, linking, whatever) asynchronously. After the build Task is done (whether it succeeded, or aborted), it should notify your application with the results.

Once your application starts that method, it would immediately return to waiting for user interactions. The build process carries on asynchronously.

If you wanted to get fancier, you could structure the build as a task for each module, with dependencies respected by having it invoke the build of module B only after module A is successfully built, if B depends upon A, otherwise start the builds of A and B in parallel. And with each build task, perhaps it could send an Event back to your user-interface code to advise the user of it's progress.

The callback method (or whichever technique you decide to use for the build process to give it's results back to you) would include a parameter for it to indicate whether it was successful, or failed. If failed, it needs to say what failed. An alternative method would be to simply have a different callback (or event) for success, and for failure.

So, the real metal of your code is in how you call your build tools and get the results back. Obviously, it is essential that you get a result back that tells you if it failed, and what that failure was.

To get into more detail, you'd need to provide me with detail on what compiler you're calling, and how you're calling it and getting it's results back. As far as how to structure your C# code -- there're multiple ways depending upon which code techniques you want to use. The Task library, for example, has a very nice API for creating Tasks that run sequentially, in parallel, provide feedback, etc.
Otherwise, I hope this helps you a bit - best of wishes,
JH
 
Share this answer
 

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