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:

    Public Sub PreSave()
            Dim response As New String(SendRequest("presavecheck.php?id=" & PCID & "&date=" & TodaysDate))
            If response = "SAVENEWRECORD" Then
            ElseIf response = "UPDATEEXISTINGRECORD" Then
            End If
        End Try
    End Sub

Open in new window

Maybe there is a way to create and start a backgroundworker with a functions name to run. For example:

so it would do whatever the function has to do and then after that I could run something like:

Thank you.
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
You can use a thread instead and give it the name of the function to execute. It will execute the function and then just die.


Alternatively, you can call this function from backgroundworker's DoWork event handler.
VAL1NAuthor Commented:
Is it okay to define it once:

Private DataProcessingThread As Thread

and then run it multiple times like this:

DataProcessingThread = New Thread(AddressOf PreLoad)
        DataProcessingThread.IsBackground = True
        DataProcessingThread = New Thread(AddressOf PreSave)
        DataProcessingThread.IsBackground = True
VAL1NAuthor Commented:
My main concern is, if I will run it multiple times one after another, will it interrupt the previous operation?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.