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