题
解决方案
您可以在单独的线程上发出请求,这将使UI线程保持响应。完成后,您需要将响应同步回UI线程。
其他提示
BackgroundWorker 是您的朋友。
这是我使用BackgroundWorker的示例使用WebService。基本上,如果不使用单独的线程,就无法在UI端进行密集操作。 BackgroundWorker是在单独的线程上运行的最好方式。
要拥有自适应用户界面,您必须使用其他线程。
但是如果你使用visual studio,生成的客户端类会有异步方法签名,它会为你做。如果你的方法是 <!>“GetData <!>”;然后你应该有一个名为<!>的方法; GetDataAsync <!> quot;这不会冻结你的窗户。
以下是一个例子:
WsClient client;
protected override void Load() {
base.Onload();
client = new WsClient();
client.GetDataCompleted += new GetDataCompletedEventHandler(client_GetDataCompleted);
}
//here is the call
protected void Invoke()
{
client.GetDataAsync(txtSearch.Text);
}
//here is the result
void client_GetDataCompleted(object sender, GetDataCompletedEventArgs e)
{
//display the result
txtResult.Text = e.Result;
}
不隶属于 StackOverflow