服务中的整个代码是
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.
While 1 = 1
Try
Dim mLoop As New Init
Catch ex As Exception
End Try
End While
End Sub
在Init构造函数上我有代码
Public Sub New()
Dim rIni As New cIniFile
Dim strPath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
strPath = New Uri(strPath).LocalPath
rIni.Filename = strPath & "\Configuration.ini"
rIni.LoadFromFile()
' TIME FOR Advertising
If (Format(Date.Now, "dddd") = "Monday" And rIni.ReadString("SMS_Advertise", "ADV_Mo", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Tuesday" And rIni.ReadString("SMS_Advertise", "ADV_Tu", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Wednesday" And rIni.ReadString("SMS_Advertise", "ADV_We", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Thursday" And rIni.ReadString("SMS_Advertise", "ADV_Th", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Friday" And rIni.ReadString("SMS_Advertise", "ADV_Fr", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Saturday" And rIni.ReadString("SMS_Advertise", "ADV_Sa", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Sunday" And rIni.ReadString("SMS_Advertise", "ADV_Su", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Then
ProcessStart(strPath & "\tSMSAdvertise.exe")
End If
' TIME FOR Notifications
If (Format(Date.Now, "dddd") = "Monday" And rIni.ReadString("SMS_Notification", "ADV_Mo", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Tuesday" And rIni.ReadString("SMS_Notification", "ADV_Tu", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Wednesday" And rIni.ReadString("SMS_Notification", "ADV_We", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Thursday" And rIni.ReadString("SMS_Notification", "ADV_Th", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Friday" And rIni.ReadString("SMS_Notification", "ADV_Fr", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Saturday" And rIni.ReadString("SMS_Notification", "ADV_Sa", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
(Format(Date.Now, "dddd") = "Sunday" And rIni.ReadString("SMS_Notification", "ADV_Su", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Then
ProcessStart(strPath & "\tSMSDate.exe")
End If
End Sub
Private Sub ProcessStart(path As String)
Dim proc As New Process
proc = Process.Start(path)
proc.WaitForExit()
End Sub
但是,在安装该服务后,我有启动它的问题。我无法弄清楚它弹出的原因
服务未及时响应启动或控制请求 时尚
在事件记录器中,我没有任何内容,而是在
下的图片上显示我也检查了主要子,而不是调试模式
Shared Sub Main()
'#If DEBUG Then
' Dim servicio As New Service1
' servicio.OnStart(Nothing)
' System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
'#Else
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
'#End If
End Sub
任何人都知道我错过了什么。
答案 0 :(得分:2)
如果您的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.
dim T as new Thread(AddressOf MainWorker)
T.Start()
End Sub
Private Sub MainWorker()
While 1 = 1
Try
Dim mLoop As New Init
Catch ex As Exception
End Try
End While
End Sub