停止在应用程序中执行进程 [英] Stopping execution of process in application

查看:70
本文介绍了停止在应用程序中执行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows窗体有两个按钮:开始按钮和停止。如何在不关闭整个应用程序的情况下停止表格

做任何事情?

停止按钮必须停止正在另一个

类中运行的进程,而不是从表单中运行。

谢谢。

解决方案




这取决于正在运行的流程。

我建议你在这个过程中运行一个工作线程并使用某种

同步机制来通知进程它应该停止

(也许是ManualResetEvent)。

或者,如果你很小心你可以使用Thread.Abort(不推荐)。


-

Miha Markic [MVP C#] - RightHand .NET咨询&开发

miha at rthand com
www.rthand.com


VMI < VO ****** @ yahoo.com>在消息中写道

新闻:OM ************* @ TK2MSFTNGP09.phx.gbl ...

我的Windows窗体有两个按钮:开始和停止。如何在不关闭整个应用程序的情况下阻止
表单执行任何操作?
停止按钮必须停止一个'正在另一个类中运行的进程,而不是在表单中运行。
谢谢。



VMI< vo ****** @ yahoo.com>写道:

我的Windows窗体有两个按钮:开始按钮和停止。如何在不关闭整个
应用程序的情况下阻止表单执行任何操作? 停止按钮必须停止在另一个类中运行的进程,而不是从表单中运行。




你的意思是实际的其他进程或者只是另一个线程?


看看
http://www.pobox.com/~skeet/csharp/m...worker.threads

for代码可以优雅地关闭工作线程。


-

Jon Skeet - < sk *** @ pobox.com>
< a rel =nofollowhref =http://www.pobox.com/~skeettarget =_ blank> http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


这只是另一个过程。我没有使用线程。


" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...

VMI< vo ****** @ yahoo.com>写道:

我的Windows窗体有两个按钮:开始按钮和停止。如何在不关闭整个
应用程序的情况下阻止表单执行任何操作? 停止按钮必须停止在另一个类中运行的进程,而不是从表单中运行。



是指实际的其他进程,还是另一个进程线程?

看看
http://www.pobox.com/~skeet/csharp/m...worker.threads
用于正常关闭工作线程的代码。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件



My Windows form has two buttons: "Start" and "Stop". How can I stop the form
from doing whatever it is doing without closing the whole application? The
"Stop" button would have to stop a process that''s being run in another
class, not from within the form.
Thanks.

解决方案

Hi,

It depends on the process being run.
I suggest you to run the process within a worker thread and use some sort of
synchronization mechanism to inform the process that it should stop
(ManualResetEvent perhaps).
Or, if you are careful enough you might use Thread.Abort (not recommended).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"VMI" <vo******@yahoo.com> wrote in message
news:OM*************@TK2MSFTNGP09.phx.gbl...

My Windows form has two buttons: "Start" and "Stop". How can I stop the form from doing whatever it is doing without closing the whole application? The
"Stop" button would have to stop a process that''s being run in another
class, not from within the form.
Thanks.



VMI <vo******@yahoo.com> wrote:

My Windows form has two buttons: "Start" and "Stop". How can I stop
the form from doing whatever it is doing without closing the whole
application? The "Stop" button would have to stop a process that''s
being run in another class, not from within the form.



Do you mean an actual other process, or just another thread?

Have a look at
http://www.pobox.com/~skeet/csharp/m...worker.threads
for code to shut down a worker thread gracefully.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


It''s just another process. I''m not using threads.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...

VMI <vo******@yahoo.com> wrote:

My Windows form has two buttons: "Start" and "Stop". How can I stop
the form from doing whatever it is doing without closing the whole
application? The "Stop" button would have to stop a process that''s
being run in another class, not from within the form.



Do you mean an actual other process, or just another thread?

Have a look at
http://www.pobox.com/~skeet/csharp/m...worker.threads
for code to shut down a worker thread gracefully.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



这篇关于停止在应用程序中执行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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