取消多层环境中的后台工作者 [英] Cancel Background worker in multi tier environment

查看:57
本文介绍了取消多层环境中的后台工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我启动BackGroundWorker来填充网格。它开始于

ui层


线程跟随(想不出更好的词)路径


UI-> Layer1-> Layer2->通讯层

它阻塞(服务器执行的东西需要

时间)


如何取消这个后台工作者?

无论如何我可以访问

后台工作者使用的线程对象然后停下来?

如果我可以有什么东西用它吗?


TIA


I start a BackGroundWorker to populate a grid. It is started off in
the ui layer

The thread follows( cannot think of a better word) the path

UI->Layer1->Layer2->Communication Layer

and it blocks (the server is executing somthing where which takes
time)

How do i cancel this background worker?
Is there anyway i can access the thread object used by the
backgroundworker and then stop it?
if i can is there anything wroong with it?

TIA

推荐答案

parez,


好​​吧,吨。调用服务器的机制是否提供了取消

的方法呢?如果有,那么这意味着有一个异步方法来调用服务器,你应该利用它,而不是

使用BackgroundWorker(它这里没有给你任何东西。


如果它没有办法异步调用,那么我会使用

BackgroundWorker (或其他一些异步机制)然后只是

如果你想取消操作就忽略它。


事情是,你做的是什么吗?还需要在

服务器上取消吗?如果是这样,你将不得不在

服务器上回滚更改,或者告诉服务器以某种方式停止。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard。 caspershouse.com


" parez" < ps ***** @ gmail.com在留言中写道

news:89 ************************* ********* @ 79g2000h sk.googlegroups.com ...
parez,

Well, tons. Does the mechanism to call the server offer a way to cancel
it? If there is, then this implies that there is an asynchronous method for
calling the server, and you should be taking advantage of that, and not
using the BackgroundWorker (it''s not giving you anything here).

If it doesn''t have a way to be called asynchronously, then I would use
the BackgroundWorker (or some other asynchronous mechanism) and then just
ignore it if you want to cancel the operation.

The thing is, are you doing anything that you need to cancel on the
server as well? If so, you are going to have to roll back the change on the
server, or tell the server to stop somehow.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"parez" <ps*****@gmail.comwrote in message
news:89**********************************@79g2000h sk.googlegroups.com...

>

我启动一个BackGroundWorker来填充网格。它开始于

ui层


线程跟随(想不出更好的词)路径


UI-> Layer1-> Layer2->通讯层

它阻塞(服务器执行的东西需要

时间)


如何取消这个后台工作者?


无论如何我可以访问
$使用的线程对象b $ b backgroundworker然后停下来吗?

如果我有什么东西可以用呢?


TIA
>
I start a BackGroundWorker to populate a grid. It is started off in
the ui layer

The thread follows( cannot think of a better word) the path

UI->Layer1->Layer2->Communication Layer

and it blocks (the server is executing somthing where which takes
time)

How do i cancel this background worker?
Is there anyway i can access the thread object used by the
backgroundworker and then stop it?
if i can is there anything wroong with it?

TIA



6月3日下午2:19,Nicholas Paldino [.NET / C#MVP]

< m ... @ spam.guard.caspershouse.comwrote:
On Jun 3, 2:19 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

parez,
parez,


好​​吧,吨。调用服务器的机制是否提供了取消

的方法呢?如果有,那么这意味着有一个异步方法来调用服务器,你应该利用它,而不是

使用BackgroundWorker(它这里没有给你任何东西。
Well, tons. Does the mechanism to call the server offer a way to cancel
it? If there is, then this implies that there is an asynchronous method for
calling the server, and you should be taking advantage of that, and not
using the BackgroundWorker (it''s not giving you anything here).



没有办法把它叫掉。(按原样)通讯层是

阻止读取。

No there is no way to call it off.(as is) The communication layers is
blocking on a read.


如果它没有办法异步调用,那么我会使用

BackgroundWorker(或其他一些异步机制)然后只是

如果你想取消操作就忽略它。
If it doesn''t have a way to be called asynchronously, then I would use
the BackgroundWorker (or some other asynchronous mechanism) and then just
ignore it if you want to cancel the operation.



我想到了。由于这是一个winforms应用程序(而不是一个网络应用程序),我认为
认为还有一个额外的线程存在狂野不应该是一个很大的问题。但正如你正确猜到我需要在服务器上取消请求


I thought about it.Since this is a winforms app(and not a web app) , i
thought one extra thread living in the wild shouldnt be a big
problem. But as you correctly guessed I need to cancel the request
also on the server.


事情是,你做的是什么吗?还需要在

服务器上取消吗?如果是这样,您将不得不在

服务器上回滚更改,或者告诉服务器以某种方式停止。
The thing is, are you doing anything that you need to cancel on the
server as well? If so, you are going to have to roll back the change on the
server, or tell the server to stop somehow.



不需要回滚。只需确保SQL

查询(需要一段时间才能执行)停止。

我通过TCP / IP连接到服务器

There are no rolls backs needed. Just need to make sure that SQL
query, which is taking sometime to execute, stops.
I am connecting to the server over TCP/IP


-

- Nicholas Paldino [.NET / C#MVP]

- m ... @ spam.guard.caspershouse。 com


" parez" < psaw ... @ gmail.com写信息


新闻:89 *********************** *********** @ 79g2000h sk.googlegroups.com ...
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"parez" <psaw...@gmail.comwrote in message

news:89**********************************@79g2000h sk.googlegroups.com...

我启动BackGroundWorker来填充网格。它开始于

ui层
I start a BackGroundWorker to populate a grid. It is started off in
the ui layer


线程跟随(想不出更好的词)路径
The thread follows( cannot think of a better word) the path


UI-> Layer1-> Layer2->通信层
UI->Layer1->Layer2->Communication Layer


并且它阻塞(服务器执行的东西需要

时间)
and it blocks (the server is executing somthing where which takes
time)


如何取消这个后台工作者?
How do i cancel this background worker?


无论如何我可以访问

后台工作者使用的线程对象然后停止它吗?

如果我能有什么东西可以用吗?
Is there anyway i can access the thread object used by the
backgroundworker and then stop it?
if i can is there anything wroong with it?


TIA
TIA


parez,


你说没有办法取消对服务器的操作,但

有一种方法可以异步执行查询。您可以在SqlCommand上使用

BeginExecute方法异步执行查询,

不需要BackgroundWorker(IMO)。


基本上,如果你取消,那么只要在它返回时忽略对

异步方法的回调(你会有一个标志,回调

会检查看到如果操作被取消或没有)。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" parez" < ps ***** @ gmail.comwrote in message

news:f3 ************************* ********* @ w7g2000h sa.googlegroups.com ...
parez,

You said that there is no way to cancel the operation to the server, but
there is a way to execute the query asynchronously. You can use the
BeginExecute methods on SqlCommand to execute the queries asynchronously,
there is no need for the BackgroundWorker (IMO).

Basically, if you cancel, then just ignore the callback to the
asynchronous method when it returns (you would have a flag that the callback
would check to see if the operation was cancelled or not).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"parez" <ps*****@gmail.comwrote in message
news:f3**********************************@w7g2000h sa.googlegroups.com...

6月3日下午2:19,Nicholas Paldino [。 NET / C#MVP]"

< m ... @ spam.guard.caspershouse.comwrote:
On Jun 3, 2:19 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

> parez,
>parez,



>好吧,吨。调用服务器的机制是否提供了取消
的方法?如果有,那么这意味着有一个异步方法
来调用服务器,你应该利用它,而不是使用BackgroundWorker(它不是在这里给你任何东西)。
> Well, tons. Does the mechanism to call the server offer a way to
cancel
it? If there is, then this implies that there is an asynchronous method
for
calling the server, and you should be taking advantage of that, and not
using the BackgroundWorker (it''s not giving you anything here).



没有办法把它关掉。(按原样)通讯层是

阻塞阅读。


No there is no way to call it off.(as is) The communication layers is
blocking on a read.


>如果它没有办法异步调用,那么我会使用BackgroundWorker(或其他一些异步机制)然后只要你想取消它就忽略它操作。
> If it doesn''t have a way to be called asynchronously, then I would
use
the BackgroundWorker (or some other asynchronous mechanism) and then just
ignore it if you want to cancel the operation.



我想到了。因为这是一个winforms应用程序(而不是一个网络应用程序),我认为
认为还有一个额外的线程存在狂野不应该是一个很大的问题。但正如你正确猜到我需要在服务器上取消请求



I thought about it.Since this is a winforms app(and not a web app) , i
thought one extra thread living in the wild shouldnt be a big
problem. But as you correctly guessed I need to cancel the request
also on the server.


>问题是,你在
服务器上做任何你需要取消的事情吗?如果是这样,您将不得不回滚
服务器上的更改,或告诉服务器以某种方式停止。
> The thing is, are you doing anything that you need to cancel on the
server as well? If so, you are going to have to roll back the change on
the
server, or tell the server to stop somehow.



不需要回滚。只需确保SQL

查询(需要一段时间才能执行)停止。


我通过TCP / IP连接到服务器

There are no rolls backs needed. Just need to make sure that SQL
query, which is taking sometime to execute, stops.
I am connecting to the server over TCP/IP


> -
- Nicholas Paldino [.NET / C#MVP]
- m ... @ spam.guard.caspershouse.com

parez < psaw ... @ gmail.com写信息

新闻:89 *************************** ******* @ 79g2000 hsk.googlegroups.com ...
>--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"parez" <psaw...@gmail.comwrote in message

news:89**********************************@79g2000 hsk.googlegroups.com...

我启动BackGroundWorker来填充网格。它开始于

ui层
I start a BackGroundWorker to populate a grid. It is started off in
the ui layer


线程跟随(想不出更好的词)路径
The thread follows( cannot think of a better word) the path


UI-> Layer1-> Layer2->通信层
UI->Layer1->Layer2->Communication Layer


并且它阻塞(服务器执行的东西需要

时间)
and it blocks (the server is executing somthing where which takes
time)


如何取消这个后台工作者?
How do i cancel this background worker?


无论如何我可以访问

后台工作者使用的线程对象然后停止它吗?

如果我能有什么东西可以用吗?
Is there anyway i can access the thread object used by the
backgroundworker and then stop it?
if i can is there anything wroong with it?


TIA
TIA



这篇关于取消多层环境中的后台工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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