我如何调用asp.net C#4.0异步方法? [英] How do I call async methods in asp.net C# 4.0?

查看:596
本文介绍了我如何调用asp.net C#4.0异步方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,与.NET 4.5就有的await,异步的关键字,允许的异步方法调用方便。我目前正在研究如何使异步调用C#4.0。我想一个例子是使一个异步调用其中的DataGrid正在数据绑定。

I'm aware that with .net 4.5 there is the await, async keywords that allows for easy calling of async methods. I 'm currently studying how to make async calls in C# 4.0. An example I want to is to make an async call where the datagrid is being databind.

如果你能提供给我一些链接我真的AP preciate它。

If you could provide me some links I would really appreciate it.

推荐答案

有一个在使用的任务,这是可以在.NET 4中,应该帮助你。一个简单的例子可能是这样的:

Have a look at using Tasks, this was available in .Net 4 and should help you. A simple example might look like this:

        public void MainFlow()
    {
        Task taskWork = Task.Run(new Action(DoWork));

        //Do other work


        //Then wait for thread finish
        taskWork.Wait();
    }


    private void DoWork()
    {
        //Do work
    }

有关更多信息,下面看看

For more, have a look here

<一个href=\"http://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.100).aspx\">http://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=vs.100).aspx

这篇关于我如何调用asp.net C#4.0异步方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆