在不更改服务合同的情况下获得 Async/Await 服务器端的好处
Gaining the server side benefits of Async/Await without changing the service contract
花了一些时间谷歌搜索这个但没有找到明确的答案并且不确定如何通过测试来证明它(欢迎提出建议)。
我们有一个 WCF 服务,它有一个等待特定事件在循环中发生的方法。在循环中,它使用 Thread.Sleep 等待几个 100 毫秒,这在服务中很长(我们想重新设计它。在服务中休眠不是个好主意,对吗?)。
我想通过使方法异步并改用 Task.Delay 来提高吞吐量,而不更改服务合同。在使方法异步并重新生成合同后 class,合同签名似乎完好无损。我还可以看到生成的代码现在有一个状态机,似乎表明它现在是异步的。
我的问题是,即使我以同步方式调用异步服务方法,我是否也能从线程可用于其他工作中获益?框架会等待服务方法吗?
Br
My question is if I will get the benefit of the thread being available for other work even if I call the async service method in a synchronous way?
So the server side benefits of a method being async are disconnected from how the client is consuming the service?
异步在服务端和客户端是独立的。服务器上的异步可实现更高的可伸缩性(这可能会或可能不会增加吞吐量)。客户端上的异步启用 UI 响应能力。
网络通信在这里是一个"divider",所以任何一方都可以异步或同步处理它,独立于另一个应用程序。
花了一些时间谷歌搜索这个但没有找到明确的答案并且不确定如何通过测试来证明它(欢迎提出建议)。
我们有一个 WCF 服务,它有一个等待特定事件在循环中发生的方法。在循环中,它使用 Thread.Sleep 等待几个 100 毫秒,这在服务中很长(我们想重新设计它。在服务中休眠不是个好主意,对吗?)。
我想通过使方法异步并改用 Task.Delay 来提高吞吐量,而不更改服务合同。在使方法异步并重新生成合同后 class,合同签名似乎完好无损。我还可以看到生成的代码现在有一个状态机,似乎表明它现在是异步的。
我的问题是,即使我以同步方式调用异步服务方法,我是否也能从线程可用于其他工作中获益?框架会等待服务方法吗?
Br
My question is if I will get the benefit of the thread being available for other work even if I call the async service method in a synchronous way?
So the server side benefits of a method being async are disconnected from how the client is consuming the service?
异步在服务端和客户端是独立的。服务器上的异步可实现更高的可伸缩性(这可能会或可能不会增加吞吐量)。客户端上的异步启用 UI 响应能力。
网络通信在这里是一个"divider",所以任何一方都可以异步或同步处理它,独立于另一个应用程序。