从应用程序或线程退出. [英] exiting from an application or a thread.

查看:63
本文介绍了从应用程序或线程退出.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于表单的应用程序中,我有一个主表单.通过单击toolstripmenuitem,它将打开另一个名为"Createenvironment"表单的表单.此createenvironment表单中有一个生成按钮,单击此按钮将编译几个c ++文件.因此,现在myrpoblem是在特定文件的编译中出现错误时,它不应继续在该列表中对即将到来的文件进行编译,并且不应关闭createenvironment表单.我只想显示错误并停止编译.

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.

推荐答案

答案似乎如此明显,以至于我认为我不了解您的问题.您显然有一个窗体(Windows窗体?),您可以在其中调用编译器.我认为您将等待编译结果以查看该窗体应如何响应-是成功还是导致错误.您能更清楚地解释一下吗?
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?


好-谢谢您的澄清.我想也许现在我明白了你的意思.

通常,对于这样的问题,我会尝试尽可能简单地构造它.对于您的情况,这是我的设想:单击开始构建的按钮时,您有一个方法可以设置回调委托或事件(构建过程将在完成时用于通知您) ,然后衍生出一个不同的过程以异步方式进行构建(编译,链接等操作).构建任务完成后(无论成功还是中止),它都应将结果通知您的应用程序.

应用程序启动该方法后,它将立即返回等待用户交互的状态.构建过程异步进行.

如果您想变得更高级,可以将构建结构作为每个模块的任务来构建,并遵循相关性,方法是只有在成功构建模块A后才让它调用模块B的构建(如果B依赖于A,否则开始构建B的构建) A和B并联.并且对于每个构建任务,也许它可以将事件发送回您的用户界面代码,以告知用户其进度.

回调方法(或您决定用于构建过程以将结果返回给您的任何技术)都将包含一个参数,以指示它是成功还是失败.如果失败,则需要说明失败的原因.另一种方法是简单地对成功和失败使用不同的回调(或事件).

因此,代码的真正精髓在于如何调用构建工具并获得结果.显然,获得结果必须告诉您是否失败以及失败的原因是很重要的.

要获得更多详细信息,您需要向我提供有关您正在调用的编译器以及如何调用它并获取其结果的详细信息.至于如何构造C#代码-有多种方法,具体取决于您要使用的代码技术.例如,任务库具有一个非常好的API,可用于创建依次运行,并行运行,提供反馈等的任务.
否则,希望对您有所帮助-致以良好的祝愿,
JH
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


这篇关于从应用程序或线程退出.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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