1
action.Invoke()
将不会调用“操作”操作,直到MethodTest退出!为什么只有在MethodTest退出时才会触发操作?
private void MethodTest(string query)
{
try
{
var webClient = new WebClient();
string webContent = string.Empty;
int index;
Action action = async delegate()
{
webContent = await webClient.DownloadStringTaskAsync(url);
//Add break point above
};
action.Invoke();
index = webContent.IndexOf("<div class=\"detName\">");
// some code here
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
}
}
注意:这将工作正常!
private async void MethodTest(string query)
{
try
{
var webClient = new WebClient();
string webContent = string.Empty;
int index;
webContent = await webClient.DownloadStringTaskAsync(url);
index = webContent.IndexOf("<div class=\"detName\">");
// some code here
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
}
}
由于我们无法在评论上设置断点,因此当您说“这里”时,是指“在上面的行上”或“在下面的行上”? –