这是我的部分代码
public MainWindow()
{
InitializeComponent();
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.site.my/install.php?data=" + uniqueID + "&pass=" + pass);
request.BeginGetResponse(new AsyncCallback(FinishWebRequest), request);
}
catch (Exception)
{
}
}
private void FinishWebRequest(IAsyncResult result)
{
HttpWebResponse response = (result.AsyncState as HttpWebRequest).EndGetResponse(result) as HttpWebResponse;
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
if (responseFromServer == "1")
{
MessageBox.show("ok")
}else{
MessageBox.show("no")
}
}
虽然我使用异步,但似乎窗口会“挂起”一段时间......所以我认为放入加载指示器会很好,对吧?我应该在哪里以及如何放置它?我想的只是一个简单的加载指示器,而不是进度条..