这是我的部分代码
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")
}
}
虽然我使用异步,但似乎窗口会“暂停”一段时间..所以我认为加载指示器会很好,对吧?我应该把它放在哪里?我只想到一个简单的加载指示器,而不是进度条..
答案 0 :(得分:0)
首先,将所有这些代码放在构造函数中是不好的做法。加载事件是这个逻辑的更合适的地方。其次,你的问题很模糊:你有什么样的装载指标?你想自己写,还是得到第三方?您究竟想要完成什么,GUI的设计是什么?
答案 1 :(得分:0)