按钮启动运行循环时如何单击按钮停止 [英] How to click button stop when button start is running loop
问题描述
我有启动和停止的程序
启动按钮而不是循环运行:
-first循环更改代理然后打开浏览器。
$ b在第一次迭代中打开的镀铬浏览器中的$ b -second循环打开URL。
停止按钮:
我希望它停止循环并重置。
我无法在启动按钮运行时按停止按钮。
我尝试过:
我尝试过背景
1-
http://stackoverflow.com/questions/3065700/how-to-start-and-stop-a-continuously-running-background-worker-using-a-button < br $> b $ b
我可以按停止但我看不到镀铬浏览器
2-
http://stackoverflow.com/questions/27580241/breaking-from-a-loop-with-button-click-c-sharp
我但我的代码而不是
Console.WriteLine(Hello,world);
当我调试代码时我自己它不会运行代码
_worker.DoWork + = new DoWorkEventHandler((state,args)=>
{});
并选择黄色。
I have program that have start and stop
start button that is run instead loop:
-first loop change proxy then open browser .
-second loop open urls in chrome browser that opened in first iteration.
stop button:
I want it stop loop and reset .
I can't press in stop button while start button is running.
What I have tried:
I tried background
1-
http://stackoverflow.com/questions/3065700/how-to-start-and-stop-a-continuously-running-background-worker-using-a-button
I can press stop but i can't see chrome browser
2-
http://stackoverflow.com/questions/27580241/breaking-from-a-loop-with-button-click-c-sharp
I but my code instead of
Console.WriteLine("Hello, world");
when i debug code i see it does't run code in
_worker.DoWork += new DoWorkEventHandler((state, args) =>
{ });
and select it with yellow color.
推荐答案
听起来你可以使用线程安全取消的异步操作的一些信息。
看看这里[线程安全操作]
需要通过查看已取消的旗帜来取消您的其他流程。
或者:如果你真的想使用后台工作人员,您可以让按钮设置一个标志,并在事件期间从后台工作人员报告进度,检查该标志,然后在该呼叫中安全取消。
Sounds like you could use some info on Asynchronous operations with thread safe cancellations.
Take a look here [Thread Safe Operations]
Need to allow the cancelling of your other process by checking the cancelled flag.
OR: if you really want to use the background worker, you can have the button set a flag and during the event to report progress from the background worker check the flag and then safe cancel within that call.
这篇关于按钮启动运行循环时如何单击按钮停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!