[RESOLVED] Create processing time limit
I have a process that recieves a request and issues a response. Sometimes createing the response is taking too long. I would like to start the request, and after 8 seconds, if the response has been created, I would abort the process and send back a generic message. All suggestions and ideas are welcome.
Re: Create processing time limit
You could capture the time before you start creating the response using Date.Now and during the creation of the response keep subtracting the initial Date you recorded from Date.Now. You would receive a TimeSpan object from which you can get how by how many seconds they differ.
Here is an example:-
vbnet Code:
'
Dim T As Date = Date.Now
'Imagine this is your long running process
Do
'End the process after 8 seconds
If (Date.Now - T).TotalSeconds >= 8 Then Exit Do
Loop
Re: Create processing time limit
you can use threading like so:
Code:
Dim MyThread As New Threading.Thread(AddressOf ProcessSub)
Try
MyThread.Start()
If MyThread.Join(8000) Then
Return True 'Complete or whatever
End If
MyThread.Abort()
Catch ex As Exception
End Try
Return False
Re: Create processing time limit
That appears to be exactly what I'm looking for, thanks Grimfort.