?
Solved

UNC Path disconnected after 10 minutes

Posted on 2007-10-20
4
Medium Priority
?
1,126 Views
Last Modified: 2012-08-14
A service that uses the FileSystemWatcher monitors a UNC Path declared in the OnStart sub. After 10 minutes the UNC path seems to be disconnected.
The service was working fine for several weeks and then suddenly the UNC Path was dropping after 10 minutes from the service starting. There are no error messages, and the service continues to run after the connection is lost.

The servers are Windows 2003 Server.
0
Comment
Question by:hertel-dev
  • 2
4 Comments
 
LVL 28

Expert Comment

by:honmapog
ID: 20115623
Check http://support.microsoft.com/kb/297684.
Set autodisconnect to a value of ffffffff.
0
 
LVL 11

Accepted Solution

by:
AkisC earned 2000 total points
ID: 20115752
FileSystemWatcher will aslo stop functioning if the computer/path that is monitoring will reboot or loose network connectivity for a moment.

A workaround is to create a timer and in a timeinterval (e.g. 1minute-60000) you stop and restart the FileSystemWatcher. That will ensure that your FileSystemWatcher will work all the time

    Private Sub TimerStartAutoWatch_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerStartAutoWatch.Tick
        Try
            stopWatching()
            Sleep(0.5)
            StartWatching()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub StartWatching()
        Try
            FileWatcherIsWorkingNow = True
            'define path
            Me.msgFileWatcher.Path = ServerWatchFolderAndPath
            Me.msgFileWatcher.Filter = "*.tmp"
            Me.msgFileWatcher.IncludeSubdirectories = True
            Me.msgFileWatcher.NotifyFilter = NotifyFilters.Size Or NotifyFilters.FileName Or NotifyFilters.DirectoryName
            ' add the handler to each event
            AddHandler msgFileWatcher.Created, AddressOf msgFileWatcher_Changed
            AddHandler msgFileWatcher.Changed, AddressOf msgFileWatcher_Changed
            'AddHandler msgFileWatcher.Renamed, AddressOf msgFileWatcher_Renamed
            'Set this property to true to start watching
            msgFileWatcher.EnableRaisingEvents = True
        Catch ex As Exception
        Finally
        End Try
    End Sub

Private Sub stopWatching()
        Dim errCounter As Long = 0
        On Error Resume Next
startStoppingAgain:
        'Set this property to false to STOP watching
        msgFileWatcher.EnableRaisingEvents = False
        RemoveHandler msgFileWatcher.Created, AddressOf msgFileWatcher_Changed
        RemoveHandler msgFileWatcher.Changed, AddressOf msgFileWatcher_Changed
        'RemoveHandler msgFileWatcher.Renamed, AddressOf msgFileWatcher_Renamed
        If Err.Number > 0 Then
            errCounter += 1
            If errCounter < 20 Then
                GoTo startStoppingAgain
            End If
        End If
        errCounter = Nothing
        On Error GoTo 0
    End Sub

I have been using this approach in my projects.
0
 

Author Comment

by:hertel-dev
ID: 20136973
honmapog:I had already tried your suggested solution with no luck.

AkisC: This is a good way of doing things. I implemented the timer code using a thread and put the polling routine in a loop. Like this:

Private m_oPollingThread As New Thread( _
            New System.Threading.ThreadStart(AddressOf pollProcess))

'placed in the sub onStart() of the service
m_oPollingThread.Start()

Private Sub pollProcess()
        Try
            Do
                ProcessFiles(Me.Path)
                System.Threading.Thread.Sleep(2000)  ' 2 seconds      
            Loop
       
        Catch ex As Exception
        End Try
    End Sub

Unfortunately I still have the same problem.
0
 
LVL 11

Expert Comment

by:AkisC
ID: 20137588
You still have the same problem , so you get an error
what does the error message say?
 Catch ex As Exception
msgbox(ex.Tostring) '// since it is a service drop the message to a file...
        End Try
-Also-
Since the UNC Path disconects at some time of inactivity, a workaround could be to write/delete a file to (Me.Path) in a time interval of less than 10 minutes, so you trick the disconnect timer. Filewatcher is just waiting...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question