ファイルが変更されるたびにダイアログを表示したい...しかし、ダイアログが表示されるたびに、アプリケーションがフリーズします。別のスレッドでどうすればいいですか?何か案は?FileSystemウォッチャー+ダイアログ
protected virtual void CreateWatcher (object path)
{
if (watcher != null)
{
watcher.EnableRaisingEvents = false;
watcher.Dispose();
}
//Create a new FileSystemWatcher.
watcher = new FileSystemWatcher();
//Set the filter to only catch TXT files.
watcher.Filter = "*.txt";
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.LastWrite;
//Subscribe to the Created event.
watcher.Changed += new FileSystemEventHandler (OnChanged);
watcher.Created += new FileSystemEventHandler (OnChanged);
//watcher.Deleted += new FileSystemEventHandler (OnChanged);
//watcher.Renamed += new RenamedEventHandler (OnRenamed);
//Set the path to C:\\Temp\\
watcher.Path = @path.ToString();
//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}
void OnChanged (object source, FileSystemEventArgs e)
{
NovaInteracaoMsg();
}
protected virtual void NovaInteracaoMsg()
{
novaInteracao = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo, "Foi detectada a mudança nos arquivos do modelo. Deseja inserir uma nova interação?");
ResponseType result = (ResponseType)novaInteracao.Run();
if (result == ResponseType.Yes) {
OpenInfoWindow (novaInteracaoPath);
return;
}
else {
novaInteracao.Destroy();
}
}
void OnRenamed (object source, RenamedEventArgs e)
{
//Console.WriteLine ("File: {0} renamed to\n{1}", e.OldFullPath, e.FullPath);
}
protected virtual void OpenInfoWindow (string path)
{
ModMemory.Iteration iterWin = new ModMemory.Iteration (path);
iterWin.Modal = true;
iterWin.Show();
iterWin.Destroyed += delegate {
// TODO: Funções para executar quando a janela for fechada
// Possivelmente atualizar o número de interações realizadas
Console.WriteLine ("Janela modal destruída");
};
}
そのダイアログは何ですか? MessageBox.Show? –
もう少し詳しく、いくつかのコード(おそらく変更が検出され、メッセージボックスが表示される場所など)が良いでしょう。 – xbonez
コードを編集するために編集しました...申し訳ありません... –