从Windows Scheduler手动启动的程序运行两次

时间:2018-01-25 19:49:46

标签: scheduled-tasks windows-server-2012

使用Windows Server 2012.我有一个Windows Scheduler任务,可以在每个月的第10天运行程序。 这最近开始发生,我不明白为什么:当我从Windows调度程序手动运行它时,它会启动两次(见图片)

无法理解发生了什么,我查看了代码,它是一个以Sub Main开头的.Net控制台应用程序(args()为String)。我没有传递任何参数,Sub Main中没有任何东西可以触发重启.... 请指教。

enter image description here

这是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)"

所以我最后收到两封电子邮件:一封报告错误,另一封报告成功。非常奇怪......

1 个答案:

答案 0 :(得分:1)

我正在回答我自己的问题,以防有人遇到同样的问题。 我刚刚删除了Windows调度程序作业并重新创建它。问题消失了。奇怪的...