2008-11-11 16 views

Respuesta

7

deberá volver a conectar con FileSystemWatcher.

Haga su variable de tipo FileSystemWatcher mundial a su clase, añadir el evento WatcherError.

Dentro del método, añadir algo así:

private static void WatcherError(object source, ErrorEventArgs e) 
    { 
    watcher = new FileSystemWatcher();//You might want to do a method and to setup all config... 
    while (!watcher.EnableRaisingEvents) 
    { 
     try 
     { 
      watcher = new FileSystemWatcher();//You might want to do a method and to setup all config... 
     } 
     catch 
     { 
      System.Threading.Thread.Sleep(30000); //Wait for retry 30 sec. 
     } 
    } 
    } 

Usted no quiere usar vigilante = new ... prefiere tener un método que agregará todo evento y configurar la ruta, pero el El código anterior le da una buena idea de qué hacer.

+0

Este código no es confiable porque FileSystemWatcher evento de error no siempre fuego cuando se controla carpeta o unidad de red. – Tomas

+0

Cuando la red está inactiva, se muestra un error. ¿Cuál es la situación en la que no es confiable? –

+0

Si FileSystemWatcher se usa para supervisar la carpeta de red, FileSystemWatcher.Error no siempre se activa si algo sale mal con la red. Este es un problema conocido y su código no se ejecutará. – Tomas

Cuestiones relacionadas