VAL1N
asked on
VB.NET Run existing functions in a background.
Hi, I have some functions that are sending requests to my webserver in order to obtain data,
however when those functions are called, form is freezing up because it's not run via backgroundworker.
Now I need to know what is the easiest way to call them functions without freezing a form.
Function example:
Maybe there is a way to create and start a backgroundworker with a functions name to run. For example:
MyBackgroundWorker.RunWork erAsync(Pr esave())
so it would do whatever the function has to do and then after that I could run something like:
MyBackgroundWorker.CancelA sync
Thank you.
however when those functions are called, form is freezing up because it's not run via backgroundworker.
Now I need to know what is the easiest way to call them functions without freezing a form.
Function example:
Public Sub PreSave()
Try
Dim response As New String(SendRequest("presavecheck.php?id=" & PCID & "&date=" & TodaysDate))
If response = "SAVENEWRECORD" Then
SavetoDB()
ElseIf response = "UPDATEEXISTINGRECORD" Then
UpdateDB()
End If
Catch
End Try
End Sub
Maybe there is a way to create and start a backgroundworker with a functions name to run. For example:
MyBackgroundWorker.RunWork
so it would do whatever the function has to do and then after that I could run something like:
MyBackgroundWorker.CancelA
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My main concern is, if I will run it multiple times one after another, will it interrupt the previous operation?
ASKER
Private DataProcessingThread As Thread
and then run it multiple times like this:
DataProcessingThread = New Thread(AddressOf PreLoad)
DataProcessingThread.IsBac
DataProcessingThread.Start
DataProcessingThread = New Thread(AddressOf PreSave)
DataProcessingThread.IsBac
DataProcessingThread.Start