0
我已经实现了一些WCF代码,它将WCF调用中的数据返回给我,它工作正常,但行为同步。异步使用来自ASP.net的WCF调用,但不能异步执行
IAsyncResult BeginGetAsyncData(object src, EventArgs args, AsyncCallback cb, object state)
{
_client = new ServiceReference1.Service1Client();
return _client.BeginGetPermissionsByStaffID("xxx", cb, state);
}
void EndGetAsyncData(IAsyncResult ar)
{
//ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
ServiceReference1.tblUser_Permission[] permissions = _client.EndGetPermissionsByStaffID(ar);
System.Threading.Thread.Sleep(2000);
dgResults.DataSource = permissions;
dgResults.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(BeginGetAsyncData, EndGetAsyncData, null, null);
Page.RegisterAsyncTask(task);
txtOut.Text = "Waiting...";
}
我所看到的是两秒钟的暂停,然后出现“等待”消息。我没有明确地产生一个新的线程,但据我所知,当我将WCF服务定义为asyncronous时,没有必要。
任何帮助,将不胜感激!
Doh!这就说得通了。我想如果你有一些可能需要一段时间的事情,它仍然是有利的。可以缩短服务器的时间,使用户看到的延迟更少。 谢谢! – 2009-10-02 17:41:35