Dear,
I have a working Module2 below, it worked when I use a button in a form to trigger the module to run 'Call Module2.Main()'.
But then when I tried to change it to run as a schedule, as usual, I change the Startup Object to use the 'Sub Main' of Module1 in Project Property. It ran but when the code reaches
the two lines:
tasks.Add(Task.Run(AddressOf NonCriminal))
tasks.Add(Task.Run(AddressOf Criminal))
, it just ran over without triggering the functions.
I have also tried compiling the project as a Console by changing the Application type, same result. Program ran, but the functions did not get triggered to run.
I know that if I don't use the ' Async Function Main() As Task' with 'Await Task.WhenAll(tasks)' approach, the scheduling will work. But I need to trace the complete time on those multithread tasks as part of my monitoring routine. Hope anyone could help to make this work.
Thanks.
Martin
Imports System.IO
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Threading
Imports System.Threading.Tasks
Module Module1
Sub Main()
Call Module2.Main()
End Sub
End Module
Module Module2
Public MIDX_Civil_Count As Integer
Public MIDX_Criminal_Count As Integer
Async Function Main() As Task
Dim i As Integer
Dim i2 As Integer
'Before starting the tasks, this section to log the start date and time worked here
'...
'...
Dim tasks As New List(Of Task)()
tasks.Add(Task.Run(AddressOf NonCriminal))
tasks.Add(Task.Run(AddressOf Criminal))
Await Task.WhenAll(tasks)
' When the tasks above end, this section to log the end date and time also worked here
'...
'...
End
End Function
Private Async Function NonCriminal() As Task
Await Task.Run(Sub()
Try
'...
Catch ex As Exception
'...
End Try
End Sub)
End Function
Private Async Function Criminal() As Task
Await Task.Run(Sub()
Try
'...
Catch ex As Exception
'...
End Try
End Sub)
End Function
End Module

