Following from Dave's suggestion, I 'think' (*tm, I'm not a VB.Net Programmer) you could do something like
' Declare a System.Threading.CancellationTokenSource.
Dim cts As CancellationTokenSource
Private Async Sub unreliableLongProcess() as Task()
' Instantiate the CancellationTokenSource.
cts = New CancellationTokenSource()
Dim token as cts.Token
Try
' Set up the CancellationTokenSource to cancel after 10 * 60 * 1000 = 10 minutes.
cts.CancelAfter(10*60*1000)
' ? is this Await redundant ?
Await Task.Run(Sub()
'
' Do slow processing here
'
token.ThrowIfCancellationRequested()
End Sub, token)
' Log/Display Process is Complete
Catch ex As OperationCanceledException
' Log/Display Process Canceled/Timed Out
Catch ex As Exception
' Log/Display Some Other Exception Occurred
End Try
' Set the CancellationTokenSource to Nothing when the process is complete.
cts = Nothing
End Sub
And use it as in
Await unreliableLongProcess()
(I was thinking about Async, Await etc in C# before Dave answered)