【发布时间】:2014-01-12 05:43:32
【问题描述】:
我的后台工作人员有问题...它只是停止...它没有通过它应该通过的所有代码...
在下面的代码中,它只是停在String gName = comboBox1.SelectedItem.ToString(); 没有任何错误.. 下面的代码根本没有运行.. 我通过在ZipFile pack = new ZipFile(); 放置一个断点来测试这个...断点没有被触发...我一遍又一遍地检查我的代码...我不知道为什么会这样...
后台工作人员:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
String appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString();
String gpsPath = appDataFolder + "/GameProfileSaver";
String userDir = gpsPath + "/profiles/" + currentUserLabel.Text;
XmlDocument doc = new XmlDocument();
doc.Load(userDir + "\\games.xml");
String gName = comboBox1.SelectedItem.ToString();
ZipFile pack = new ZipFile();
foreach (XmlNode node in doc.SelectNodes("//games/game[gameName='" + gName + "']/Files/file"))
{
try
{
if (!Directory.Exists(userDir + "\\" + gName))
{
Directory.CreateDirectory(userDir + "\\" + gName);
}
pack.AddFile(node.InnerText);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
pack.Save(userDir + "\\" + gName);
}
【问题讨论】:
-
我现在找不到任何具体的参考资料,但 IIRC
DoWork无法访问表单的元素。尝试将String gName = comboBox1.SelectedItem.ToString();放入 try/catch 中,看看会发生什么
标签: c# multithreading backgroundworker