1
我正在为ESRI ArcGIS Explorer 1200开发一个小插件。扩展本身非常简单,它只是使用FileSystemWatcher等待传入文件,然后处理文件。ArcGIS Explorer:从辅助线程调用主线程
我的主要问题是:当FileSystemWatcher事件触发时,它使用与GUI线程不同的线程。所以我无法访问与GUI相关的对象。 现在我需要一些方法来调用用户线程中的一段代码,但我不知道如何在ArcGIS世界中执行此操作。
我的扩展到目前为止是这样的:
public class MyExtension : ESRI.ArcGISExplorer.Application.Extension
{
FileSystemWatcher _fsw;
public override void OnStartup()
{
_fsw = new FileSystemWatcher(@"c:\Temp\Import", "*.xml");
_fsw.IncludeSubdirectories = false;
_fsw.Created += FileCreated;
_fsw.EnableRaisingEvents = true;
}
void FileCreated(object sender, FileSystemEventArgs e)
{
GraphicCollection graphic = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Graphics; // <-- Threading Exception happens here
MessageBox.Show(Convert.ToString(graphic.Count));
}
public override void OnShutdown()
{
_fsw.EnableRaisingEvents = false;
}
}
任何想法如何解决此问题?