XML ファイルからすべての値を非同期的に取得する小さな C# アプリケーションを作成しました。問題は..非同期ではなく、どこが間違っているのかわかりません。ボタンをクリックすると、UI がフリーズし、アプリケーションを移動できないなど、同期的に実行されているすべての兆候が示されます。
なぜこれが起こっているのか誰にもわかりますか?
private async void parseAndExportBtn_Click(object sender, EventArgs e)
{
progressBar1.MarqueeAnimationSpeed = 100;
parseAndExportBtn.Enabled = false;
selectDirectoryBtn.Enabled = false;
status.Text = "Started searching files...";
await SearchFiles(selectTxcDirectory.SelectedPath);
status.Text = "Finished searching files";
}
private static async Task SearchFiles(string path)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path + "/cen_18-2_-1-y11.xml");
using (XmlReader r = XmlReader.Create(new StringReader(xmlDoc.InnerXml), new XmlReaderSettings() { Async = true }))
{
while (await r.ReadAsync())
{
switch (r.NodeType)
{
case XmlNodeType.Text:
Console.WriteLine(await r.GetValueAsync());
break;
}
}
}
}