1

I'm working on an MVC 4 application. I've a controller where I make calls to some REST service using the HttpClient class. The controller is a normal controller and the actions are not described with async keyword. Do I get any gain of using PostAsync method of HttpClient class in this case? It's not a fire and forget call and I need the result returned from the service. The ASP.NET thread is going to be blocked anyway till it get the result and so is there advantage?

4

1 に答える 1

1

その場合、あなたには何のメリットもありません。完全に非同期にするか、完全に同期にする必要があります。

私が考えることができる唯一の例外は、数十の非同期の同時要求から開始する単一の同期 MVC アクションがある場合です。その場合、1 つのスレッドを燃やして他の何十ものスレッドを調整します。それは受け入れられるでしょう。

補足: 非同期はほとんどのサーバー アプリには適用されませんが、あなたのケースでは、潜在的に長時間実行される HTTP 要求を作成しているため、完全非同期スタイルのソリューションの恩恵を受けることができるようです。したがって、この 1 つの特定の MVC アクションに対してすべて非同期に切り替えることができます。

于 2012-12-12T12:07:08.667 に答える