VB.NET Run existing functions in a background.

Posted on 2012-09-17
Last Modified: 2012-09-17
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.
Question by:VAL1N
    LVL 83

    Accepted Solution

    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.

    Author Comment

    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

    Author Comment

    My main concern is, if I will run it multiple times one after another, will it interrupt the previous operation?

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now