【发布时间】:2013-12-13 20:19:20
【问题描述】:
我想更改 OnChanged 方法中的 GUI 属性...(实际上我试图设置图像源...但为简单起见在这里使用了一个按钮)。每次 filesystemwatcher 检测到文件中的更改时都会调用它。它会到达“顶部”输出。但在尝试设置按钮宽度时会捕获异常。
但如果我将相同的代码放在按钮中.. 它工作得很好。我真的不明白为什么..有人可以帮助我吗?
private void OnChanged(object source, FileSystemEventArgs e)
{
//prevents a double firing, known bug for filesystemwatcher
try
{
_jsonWatcher.EnableRaisingEvents = false;
FileInfo objFileInfo = new FileInfo(e.FullPath);
if (!objFileInfo.Exists) return; // ignore the file open, wait for complete write
//do stuff here
Console.WriteLine("top");
Test_Button.Width = 500;
Console.WriteLine("bottom");
}
catch (Exception)
{
//do nothing
}
finally
{
_jsonWatcher.EnableRaisingEvents = true;
}
}
我真正想做的不是改变按钮宽度:
BlueBan1_Image.Source = GUI.GetChampImageSource(JSONFile.Get("blue ban 1"), "avatar");
【问题讨论】:
标签: c# wpf filesystemwatcher