Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

System.ComponentModel.Win32Exception (0x80004005): The specified server cannot perform the requested operation

$
0
0

Greetings,

I have a program running a FileSystemWatcher to watch for changes to a log file on a mapped drive (code below).  This same program is running on three different production machines and two of them are working perfectly.

On the third machine every few seconds I receive a monitor error that contains the line;

  'System.ComponentModel.Win32Exception (0x80004005): The specified server cannot perform the requested operation'.

This message is very ambiguous and general (at least to me).  Have googled it but to no avail.  The inner exception is blank so it's of no help.

Can anyone please shed some light on what this error means and perhaps why it would be occurring?

Thank you.

Dale Hoffman

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileSystemWatcherTest
{
    class Program
    {
        static FileSystemWatcher _monitor;

        static void Main(string[] args)
        {
            StartWatcher();
            Console.WriteLine(@"Press any key to exit.");
            Console.ReadKey();
        }

        private static void StartWatcher()
        {
            try
            {
                _monitor = new FileSystemWatcher();
                //_monitor.InternalBufferSize = 16384;
                _monitor.Path = @"L:\";
                _monitor.IncludeSubdirectories = false;
                _monitor.Filter = "DPJobState*.txt";
                _monitor.NotifyFilter = NotifyFilters.LastWrite;
                _monitor.Error += OnMonitorError;
                _monitor.Changed += new FileSystemEventHandler(OnMonitorChanged);
                _monitor.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {
                _monitor.Dispose();
                using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingMonitorLog.txt", true))
                    swLog.WriteLine(DateTime.Now.ToString() + ex);
                System.Threading.Thread.Sleep(1000);
                StartWatcher();
            }
        }

        private static void OnMonitorChanged(object sender, FileSystemEventArgs e)
        {
            _monitor.EnableRaisingEvents = false;
            using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingLog.txt", true))
                swLog.WriteLine(DateTime.Now.ToString() + " Log file changed");
            _monitor.EnableRaisingEvents = true;
        }

        private static void OnMonitorError(object source, ErrorEventArgs e)
        {
            _monitor.Dispose();
            using (StreamWriter swLog = new StreamWriter(@"c:\Tools\Log\AutoCreditingErrorLog.txt", true))
                swLog.WriteLine(DateTime.Now.ToString() + " Monitor error detected: " + e.GetException());
            System.Threading.Thread.Sleep(1000);
            StartWatcher();
        }
    }
}


Dale Hoffman


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>