c#service“已达到netwerk bios命令限制”错误原因和最新解决方案是什么?

时间:2012-01-30 14:03:29

标签: c# service .net-3.5 filesystemwatcher

我有一项服务可以打开多个观察者来观看多个文件夹。在观看文件夹一段时间之后,我得到了“已达到网络bios命令限制”。

正如我在here上所读到的那样,这是因为长期请求多于允许的长期请求。

我认为这是由于我所拥有的以下错误处理代码而发生的,这是由观察者错误事件触发的。这将通过再次调用WatchFile方法启动观察程序的新实例。我相信这会使现在已经不复存在的旧观察者继续运行并启动一个新观察者,但我担心停止观察者会阻止它再次启动它,或者会根据观察者停止所有实例。

或者我错了,错误取决于更改量?这将导致100个文件同时丢失,从而导致此错误。

我想在每次运行此错误时停止并启动服务,但这不会解决问题本身,只是隐藏它。有更好的解决方案吗?

private static void watcherError(String directory, Boolean intray, ErrorEventArgs e, FileSystemWatcher watcher)
{
    Exception watchException = e.GetException();
    EventLog.WriteEntry("WhiteFileMover", String.Concat("error gedetecteerd, watcher werd herstart  -  ", watchException.Message), EventLogEntryType.Information);
    watcher = new FileSystemWatcher();
    while (!watcher.EnableRaisingEvents)
    {
        try
        {
            // This will throw an error at the
            // watcher.NotifyFilter line if it can't get the path.
            WatchFile(directory, intray);
        }
        catch(Exception exp)
        {
            // Sleep for a bit; otherwise, it takes a bit of
            // processor time
            EventLog.WriteEntry("WhiteFileMover", String.Concat("Failed to restart watcher, retrying in 5 seconds  -  ", exp.Message), EventLogEntryType.Warning);
            System.Threading.Thread.Sleep(5000);
        }
    }
}

2 个答案:

答案 0 :(得分:2)

看看这一行:

watcher = new FileSystemWatcher();

您传入了FileSystemWatcher变量,但完全忽略了传递的值。相反,您创建了一个新实例。不仅如此,您还无法正确处置实例。我的猜测是你有一堆旧的FileSystemWatcher对象闲着等待收集。其中每个都将保留来自操作系统的一些真实文件系统资源。随着时间的推移,你的可用文件句柄用完了。

答案 1 :(得分:0)

为什么不创建filewatcher并定义事件处理程序?

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx