.NET Windows服务重新启动服务器

时间:2012-12-02 20:43:38

标签: .net vb.net windows-services

我开发了一个Windows服务,它可以在预定的基础上备份我的文件和文件夹。它执行以下任务:

1 - 读取文件夹和文件列表

2 - 将它们压缩并将它们放在临时目录中(将大文件分成50MB块)

3 - 将临时文件夹的内容上传到FTP

4 - 删除临时文件夹

现在临时文件夹的大小约为3GB,服务每天运行两次。现在我的服务器随机重启(不是在服务创建或上传数据期间),我开始认为这可能是I / O问题导致我的服务器重新启动。

在.NET中优化我的服务器的最佳方法是什么?我可以将PriorityClass设置为BelowNormal,但我认为它不会有帮助。我的onStart看起来像这样......

Protected Overrides Sub OnStart(ByVal args() As String)
    ' Add code here to start your service. This method should set things
    ' in motion so your service can do its work.
    Try
        Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal
        Dim s As New BackupLibraryV2.main
    Catch ex As Exception
        BackupLibraryV2.util.LogEntry("", ex.Message, DateTime.Now, DateTime.Now)
    End Try

End Sub

(我应该在新线程中启动服务吗?)

我是否还有其他建议可以尝试优化我的服务器以降低CPU密集度?

这是重启日志:

crash dump file: C:\Windows\Minidump\120212-14227-01.dmp
This was probably caused by the following module: ntoskrnl.exe (nt+0x7EFC0) 
Bugcheck code: 0x3B (0xC0000005, 0xFFFFF800019A7382, 0xFFFFF88008DFA9E0, 0x0)
Error: SYSTEM_SERVICE_EXCEPTION
file path: C:\Windows\system32\ntoskrnl.exe
product: Microsoft® Windows® Operating System
company: Microsoft Corporation
description: NT Kernel & System
Bug check description: This indicates that an exception happened while executing a routine that transitions from non-privileged code to privileged code. 
This appears to be a typical software driver bug and is not likely to be caused by a hardware problem. 
The crash took place in the Windows kernel. Possibly this problem is caused by another driver that cannot be identified at this time.

1 个答案:

答案 0 :(得分:3)

崩溃不太可能是由您的应用程序代码引起的。事件日志中的语句

  

这似乎是典型的软件驱动程序错误

可能就在现场。

由于您的应用程序正在执行相当数量的IO,因此它可能触发 IO子系统驱动程序中的问题。您是否有一个IO系统使用未作为Windows安装的一部分提供的驱动程序,或者您是否更新了制造商的IO驱动程序?如果是这样,请尝试运行旧版本的驱动程序。

  

我应该在新线程中启动服务吗?

您的OnStart事件处理程序应立即将控制权返回给系统。在单独的线程上进行处理。

  

我可以将PriorityClass设置为BelowNormal,但我认为它不会有帮助

对于像这样的后台任务来说,BelowNormal可能是一个合理的设置(取决于服务器的其他功能),但是你是对的,它根本不会影响服务器重启。

  

我是否还有其他建议可以尝试优化我的服务器以降低CPU密集度?

您为什么关注CPU利用率?它来自ZIP操作吗?如果是这样,您可以考虑使用7Zip。它是免费的,可以从命令行调用或从.NET程序链接,并使您能够设置所需的压缩级别(更高的压缩=更多的CPU和内存使用),并允许您控制的数量用于压缩的线程。如果需要,它与ZIP兼容,并且还提供卓越的专有.7z压缩格式。