Hi, I've created an application which shows a chart on a form.
The data used to populate the chart is from a sql database query.
The query takes about 15 seconds to run so i wanted to show a dialog box while the query is running.
I found an example on the web which can pop up a dialog box with a progress bar, and it wont freeze the application - msdn.microsoft.com/en-us/library/5c9654de.aspx
I thought I could replace the code which pauses the form in the example with my function name. When I replace the sleep timer with my function call I get the error.
Additional information: The calling thread must be STA, because many UI components require this.
Below is my code.
Thanks very much
' Initialize the dialog that will contain the progress bar Dim progressDialog As New ProgressDialog() ' Initialize the thread that will handle the background process Dim backgroundThread As New Thread(New ThreadStart(Function() ' Set the flag that indicates if a process is currently running isProcessRunning = True ' Set the dialog to operate in indeterminate mode progressDialog.SetIndeterminate(True) ' Run My function with my SQL query to create chart CreateMyChart() ' Show a dialog box that confirms the process has completed MessageBox.Show("Thread completed!") ' Close the dialog if it hasn't been already If progressBar1.InvokeRequired Then progressDialog.BeginInvoke(New Action(Sub() progressDialog.Close())) End If ' Set the dialog to operate in indeterminate mode ' Reset the flag that indicates if a process is currently running isProcessRunning = False End Function))