找不到“Sub Main”。服务管理控制台应用错误?

时间:2013-05-08 15:58:44

标签: vb.net service console

下面可能有一些问题。没有机会测试/调试代码,因为无法运行它。它说明没有找到主要方法。但是还有?我甚至把它改成了共享等等。这可能是显而易见的事情了吗?

它正在标记 - 在'ConsoleApplication1.Module1'错误中找不到'Sub Main'。

另外,主要的方法并不总是一个单独的类,我只是在尝试。我正在导入一个引用 - system.processes。最初是作为vb.form创建的,但实现了我不想要表单部分并重新创建为控制台应用程序(这很可能是问题所在,因为它是我已经完成的第一个控制台应用程序之一)。

代码基本上计划用于服务死亡。报告并尝试管理重启(未完成,欢迎提示)。

Imports System
Imports System.Management
Imports System.ServiceProcess
Imports System.Diagnostics
Imports System.Threading
Imports System.IO

Module Module1


Public Class Control


    Public Sub Main()              'Public Sub Main(ByVal sArgs() As String)
        Dim restart As New Rest

        restart.startTime = DateTime.Now()
        restart.cr20Services()
        restart.Report()
    End Sub

End Class

Public Class Rest
    public startTime As String
    Dim logPath As String = "C:\cr20\restart.txt"
    'Dim fileExists As Boolean = File.Exists(strFile)
    Dim arrcr20ServicesInitialStatus As New ArrayList
    Dim failedServices As New ArrayList
    Dim arrcr20Services As New ArrayList


    Public Sub cr20Services()

        'cr20 Services
        arrcr20Services.Add("cr20 service")
        arrcr20Services.Add("cr20 router")


        For Each cr20Service In arrcr20Services

            arrcr20ServicesInitialStatus.Add(cr20Service & " - " & cr20Status(cr20Service))
            cr20Restore(cr20Service)

        Next


    End Sub

    Private Function cr20Status(ByVal cr20Service As String)

        Dim service As ServiceController = New ServiceController(cr20Service)

        Return service.Status.ToString


    End Function



    Private Sub cr20Restore(ByVal cr20Service As String)

        Dim service As ServiceController = New ServiceController(cr20Service)

        'Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("calc") 

        If (service.Status.Equals(ServiceControllerStatus.Stopped)) Or (service.Status.Equals(ServiceControllerStatus.StopPending)) Then

            failedServices.Add(service)
            service.Stop()
            Thread.Sleep(10000)     'give service 10 seconds to stop
            service.Start()

        End If

    End Sub

0 个答案:

没有答案