取消异步远程调用

发布于 2024-07-08 22:27:15 字数 253 浏览 3 评论 0原文

我有一个客户端-服务器架构,其中客户端使用 .NET Remoting 与服务器进行通信。 服务器处理所有业务逻辑和数据库交互。 我需要添加一个操作,该操作可能需要一段时间才能执行,并且它返回的数据集可能非常大。 我正在考虑为此采用异步调用。 现在问题出现了:假设客户端进行了这个异步调用,操作启动了 SQL 查询,并且用户关闭客户端或单击“取消”——操作会发生什么? 有什么方法可以取消正忙于与 SQL Server 通信的待处理异步调用吗?

谢谢。

I have a client-server architecture where client communicates with the server using .NET Remoting. Server handles all business logic and database interaction. I need to add an operation which may take a while to execute and the dataset it returns might be quite large. I'm thinking of employing asynchronous call for that. Now the problem arises: assume, the client made this async call, operation started SQL query, and user either closes the client or clicks Cancel -- what will happen to the operation? Is there any way to cancel the pending async call, which is busy talking to SQL server?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一枫情书 2024-07-15 22:27:15

您可以设计客户端/服务器交互,以便服务器让工作线程执行 SQL 操作,以便准备好接收来自客户端的另一个调用。 因此,客户端拨打电话 1 并说执行 SQL 工作。 服务器将该工作交给工作线程并准备好接收新的传入。 然后客户拨打电话 2 并说“没关系”。 服务器将进行一些记录,以确保工作线程完成时不会回调客户端。

服务器能否安全地中断工作线程。 我不知道。 这会对 SQL Server 正在执行的操作产生任何影响吗? 没有把握。

You could design your client/server interaction so that the server let a worker thread do the SQL stuff so that it was ready to receive another call from the client. So, the client makes call 1 and says do SQL work. The server gives that work to the worker thread and is ready for new incoming. Then the client makes call 2 and says, "never mind". The server would do some bookkeeping to make sure it doesn't call back to the client when the worker thread is done.

Can the server safely interrupt the worker thread. I'm not sure. Would that have any affect on what SQL Server is doing. Not sure.

懵少女 2024-07-15 22:27:15

当客户关闭应用程序时,您现在对正在进行的呼叫做什么? 您可以使用异步调用执行相同的操作。

是的,异步是处理长时间运行的请求的方法。 如果结果集足够大,您甚至可以考虑发送其中的块以及来自服务器的多个响应。

当用户单击“取消”时,您将向服务器发送一条新消息,表明您不再对结果感兴趣。 如果 SQL 请求正在线程池上运行,则无法真正取消它。

What do you do now with call in progress when client closes application? You can do the same thing with asynchronous call.

Yes, async is the way to go for long-running requests. If result set is big enough, you can even think about sending chunks of it with several responses from server.

Of when user clicks Cancel, you would send a new message to the server stating you are not interested in results anymore. If the SQL request is running on thread pool, you cannot really cancel it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文