I'm developing a small add-in for ESRI ArcGIS Explorer 1200. The extension itself is quite simple, it just uses a FileSystemWatcher to wait for an incoming file, then processes the file.
My main problem is: When the FileSystemWatcher event fires, it uses a different thread than the GUI-thread. So I can't access GUI-related objects. Now I would need some way to invoke a piece of code in the user thread, but I don't know how to do this in ArcGIS world.
My extension so far looks like this:
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;
}
}
Any ideas how to work around this?