【发布时间】:2018-01-25 19:49:45
【问题描述】:
使用 Windows Server 2012。我有一个 Windows 调度程序任务,该任务在每个月的第 10 天运行一个程序。 最近开始发生这种情况,我不明白为什么:当我从 Windows 调度程序手动运行它时,它会启动两次(见图)
无法理解发生了什么,我查看了代码,它是一个以 Sub Main(args() as String) 开头的 .Net 控制台应用程序。我没有传递任何参数,并且 Sub Main 中没有任何内容会触发重新启动.... 请指教。
这是 Sub Main() 中的代码
Sub Main(args As String() = Nothing)
Dim inputFile As String, sErr As String = vbNullString, bOk As Boolean =
True
Dim ID As Integer, currentRow As String = Nothing, sLogFilePath As String
= vbNullString, sNewName As String = vbNullString, i As Integer
Dim bDownloadData As Boolean = True
Dim watch As Stopwatch = Stopwatch.StartNew()
If args.Count > 0 Then bDownloadData = CBool(args(0))
If bDownloadData Then
'run P6 report to get list of Active Reports
sLogFilePath = P6_PATH & "myLog.txt"
Console.WriteLine("Get list Of active projects")
ID = Shell(P6_PATH & "runbatch_Active_Projects.bat", AppWinStyle.NormalFocus, True, -1)
Console.WriteLine("Active Projects extract/P6 Client Return code: " & ID & vbCrLf)
'read myLog.txt to see if completed without errors
If File.Exists(sLogFilePath) Then
Using MyReader As New StreamReader(sLogFilePath, Encoding.Default)
While Not MyReader.EndOfStream
'read current row until the last
currentRow = MyReader.ReadLine
End While
MyReader.Close()
MyReader.Dispose()
End Using
If InStr(1, currentRow, "Returning Exit Code: 0", CompareMethod.Text) = 0 Then
Console.WriteLine("An error has occurred extracting Active Projects: " & currentRow)
SendMail1("Active Projects extraction error", currentRow)
Exit Sub
End If
End If
End If
ReadExcelFile ("BWMP_main.xlsx")
SendMail1("Success)"
End Sub
发生的事情是这样的;执行以下代码行:
SendMail1("Active Projects extraction error", currentRow)
我收到一封带有错误代码的电子邮件,但随后...程序重新启动并执行到最后没有任何问题,这行代码也执行:
SendMail1("Success)"
所以我最终收到了两封电子邮件:一封报告错误,另一封报告成功。很奇怪……
【问题讨论】:
-
是不是不小心把它添加到调度器了两次?
-
刚刚检查过:不,它只出现一次。我手动启动它:right_click->Run
-
我能想到的唯一其他选择是发布代码,以便我们更好地提供帮助。
-
我发布了代码。
标签: scheduled-tasks windows-server-2012