views:

202

answers:

2

Hi All

I am using standalone application vb.net(2.0) and using filesysystem watcher class to find any new xml coming into that specified directory then application take that file and continue the process but the direcotry have been located in network machine,

Now my problem is

once the path is not available it mean the shared path server going to offline, then my application not intemate me, how could i chage my code,

any one have idea, please share to me

Thanks in Advance Nanda.A

A: 

You need check the availability of your net share. FYI: http://stackoverflow.com/questions/458363/determining-if-file-exists-using-c-and-resolving-unc-path

PerlDev
+2  A: 

If you're listening for changes on a directory and it becomes unavailable (like the server being restarted), the FileSystemWatcher will throw an Exception. It provides a OnError event that you can listen for and you can decide how to handle the problem.

I have an application that runs multiple watchers and when one errors the application will handle the error by looping every 30 seconds attempting to connect again. It also keeps a running total of the number of times it has tried to connect unsuccessfully and eventually will give up (after about an hour).

Here's the general idea in VB.Net:

''' <summary>
''' This event is called when an error occurs with the file watcher. Most likely the directory being watched is no longer available (probably from a server reboot.)
''' </summary>
Protected Sub Scan_Error(ByVal Source As FileSystemWatcher, ByVal E As ErrorEventArgs)

    '// Stop listening
    Source.EnableRaisingEvents = False

    '// Maximum attempts before shutting down (one hour)
    Dim Max_Attempts As Integer = 120
    Dim Timeout As Integer = 30000
    Dim I As Integer = 0

    '// Attempt to listen - if fail, wait and try again in 30 seconds.
    While Source.EnableRaisingEvents = False And I < Max_Attempts
        I += 1

        Try
            Source.EnableRaisingEvents = True
        Catch
            Source.EnableRaisingEvents = False
            System.Threading.Thread.Sleep(Timeout)
        End Try
    End While
End Sub
Lance McNearney