user5326167
user5326167

Reputation:

Program started manually from Windows Scheduler runs twice

Using Windows Server 2012. I have a Windows Scheduler task that runs a program on 10-th day of each month. This started to happen recently and I don't understand why: when I run it manually from Windows scheduler, it starts twice (see picture)

Cannot understand what is going on, I looked through the code, it is a .Net console application that starts with Sub Main(args() as String). I don't pass any arguments and there is nothing in Sub Main that would trigger a restart.... Please advise.

enter image description here

This is the code in 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

What happens is this; the following line of code executes:

 SendMail1("Active Projects extraction error", currentRow)

And I get an e-mail with the error code but then... the program just restarts and executes to the end without any problem and this line of code also executes:

   SendMail1("Success)"

So I end-up with two emails: one reporting an error, and a second one reporting success. Very weird...

Upvotes: 2

Views: 1143

Answers (1)

user5326167
user5326167

Reputation:

I am answering my own question in case somebody experiences the same issue. I just deleted the Windows scheduler job and re-created it. Problem went away. Weird...

Upvotes: 1

Related Questions