【问题标题】:web api asynchronous method from .net application来自.net应用程序的web api异步方法
【发布时间】:2014-04-18 20:30:36
【问题描述】:

我有一个 web api 2 应用程序和一个 wpf 客户端。我的问题是 LINQ to Entities 支持多种异步方法,如 ToListAsync、ToArrayAsync 等。

但在我的 wpf 客户端应用程序中,没有这样的东西。

谁能给我一些客户端应用程序中异步方法的例子?

【问题讨论】:

  • 实际上,异步方法非常适用于 WPF 应用程序,以便 UI 线程可以在任何后台调用正在进行时保持响应。看看this msdn example for wpf

标签: c# asynchronous asp.net-web-api


【解决方案1】:

Web API 调用只是直接的 HTTP 调用。只需使用HttpClient 类。

Asynchronous coding reference

Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");

// You can do work here that doesn't rely on the string from GetStringAsync.
DoIndependentWork();

string urlContents = await getStringTask;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多