执行异步操作

发布于 2024-09-11 05:43:03 字数 615 浏览 3 评论 0原文

我读过有关执行异步操作的内容,我发现它可以在 SQL 命令执行端完成(在执行 SQL 命令期间通过添加等待 AsynchResult 的等待句柄进行处理)或从 UI 执行端完成(通过使用指向方法的委托然后开始异步调用方法)如下所示:

SQL 端(通过在 SQL 命令中使用等待句柄和 DELAYFOR): http://msdn.microsoft.com/ en-US/library/yws6262h%28v=VS.80%29.aspx

UI 端: http://msdn.microsoft.com/ en-US/library/2e08f6yc%28v=VS.80%29.aspx

但我不知道哪个在性能和运行时方面更好?

谁能告诉我在性能方面的差异吗?这种技术和线程池队列技术哪个更好?

提前致谢

I have read about executing asynchronous operations and i found that it can be done at the SQL command executions side(that is handled during executing SQL command by adding wait handle that waits for AsynchResult) or from the UI execution side(which is done by using delegate that points to a method then begin invoke methods asynchronously) like the following :

SQL side(by using wait handle and DELAYFOR in the SQL command):
http://msdn.microsoft.com/en-US/library/yws6262h%28v=VS.80%29.aspx

UI side:
http://msdn.microsoft.com/en-US/library/2e08f6yc%28v=VS.80%29.aspx

but i don't know which is better with respect to the performance and runtime?

Can any one tell me the differences with respect to the performance perspective? and which is better also this technique or thread pool queue technique ?

Thanks in advance

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

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

发布评论

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

评论(1

最后的乘客 2024-09-18 05:43:03

假设“SQL 端”指的是 SqlCommand 对象上的 BeginXXX EndXXX 方法,而 UI 则意味着异步执行的委托 - 只需使用一个与另一个。两者之间的性能差异仅与您运行的代码有关 - SQL 端只会异步执行命令,UI 端可能有您提供的许多其他代码。

在很多情况下,提供比 SQL 命令更高级别的异步操作就足够了。在某些情况下,例如您的数据访问层想要一次启动多个命令,那么最好使用 SqlCommand 方法。

希望这接近您所追求的。

请注意,异步执行委托 (Delegate.BeginInvoke) 或 BeginXXX 方法将使用 ThreadPool 线程。这里快速概述了使用委托与线程池之间的区别:

http://www.toadz.dk/2010/01/delegate-begininvoke-vs-threadpool-queueuserworkitem/

Assuming by "SQL side" you mean the BeginXXX EndXXX methods on the SqlCommand object, and the UI meaning simply a delegate executed asynchronously - there is no performance difference provided by simply using one versus the other. A performance difference between the two will only be in relation to the code you run - the SQL side will only execute the command asynchronously, the UI side might have a lot of other code you provide.

In a lot of cases, it's simply enough to provide the async actions at a higher level than the SQL command. In some cases, such as your data access layer wanting to start many commands at once, it will then be good to use the SqlCommand methods.

Hopefully that's somewhere near what you are after.

Note that executing a delegate asynchronously (Delegate.BeginInvoke) or a BeginXXX method will use a ThreadPool thread. The differences between using a delegate versus the thread pool are quickly outlined here:

http://www.toadz.dk/2010/01/delegate-begininvoke-vs-threadpool-queueuserworkitem/

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