ESRI ArcGIS Explorer 1200用の小さなアドインを開発しています。拡張機能自体は非常に単純で、FileSystemWatcherを使用して着信ファイルを待機し、ファイルを処理します。
私の主な問題は次のとおりです。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;
}
}
これを回避する方法はありますか?