澳门新蒲京娱乐

新蒲京官方下载 9
Restframework框架总结及restful规范,rest_Framework框架认证源码分析

流程控制

Async方法死锁的问题

今天调节和测试requet.GetRequestStreamAsync异步方法出现不回去的难题,恐怕是死锁了。看到老外一篇小说解释了异步方法死锁的主题材料,懒的翻译,直接搬过来了。

后日调试requet.GetRequestStreamAsync异步方法出现不回去的题材,也许是死锁了。看到老外1篇文章解释了异步方法死锁的难点,懒的翻译,直接搬过来了。

This is a problem that is brought up repeatedly on the forums and Stack
Overflow. I think it’s the most-asked question by async newcomers once
they’ve learned the basics.

This is a problem that is brought up repeatedly on the forums and Stack
Overflow. I think it’s the most-asked question by async newcomers once
they’ve learned the basics.

UI Example

Consider the example below. A button click will initiate a REST call and
display the results in a text box (this sample is for Windows Forms, but
the same principles apply to any UI application).

// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
  using (var client = new HttpClient())
  {
    var jsonString = await client.GetStringAsync(uri);
    return JObject.Parse(jsonString);
  }
}

// My "top-level" method.
public void Button1_Click(...)
{
  var jsonTask = GetJsonAsync(...);
  textBox1.Text = jsonTask.Result;
}

The “GetJson” helper method takes care of making the actual REST call
and parsing it as JSON. The button click handler waits for the helper
method to complete and then displays its results.

This code will deadlock.

UI Example

Consider the example below. A button click will initiate a REST call and
display the results in a text box (this sample is for Windows Forms, but
the same principles apply to any UI application).

// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
  using (var client = new HttpClient())
  {
    var jsonString = await client.GetStringAsync(uri);
    return JObject.Parse(jsonString);
  }
}

// My "top-level" method.
public void Button1_Click(...)
{
  var jsonTask = GetJsonAsync(...);
  textBox1.Text = jsonTask.Result;
}

The “GetJson” helper method takes care of making the actual REST call
and parsing it as JSON. The button click handler waits for the helper
method to complete and then displays its results.

This code will deadlock.

相关文章

No Comments, Be The First!
近期评论
    功能
    网站地图xml地图