(VB.NET) So I finally understand how it works, incorporated on one of my long processes and it works. Great. But now when I run the process (showing a progress bar) I can only do other tasks after the progressbar finishes. The Setup:
I have a subroutine that creates about 5 excel spreadsheet from records in a database. The progressbar shows for each file creation. As it's creating a file I can't access my Menu (File, View,etc..) until a file is done. The menu item opens but the process stops. After I release the menu item, the process continues.
The threading code is as follows:
Private Sub ExcelButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles PictureBox4.Click
Dim t As New System.Threading.Thread(AddressOf StartProcess)
t.IsBackground = True
t.Start()
End Sub
Try Dim mi As New MethodInvoker(AddressOf BuildExcelFiles)
Cursor.Current = Cursors.WaitCursor
BeginInvoke(mi)
Catch ex As Threading.ThreadInterruptedException MessageBox.Show("Friendly Message : An error has occured. _
Retry or call I.T. Support." & vbCrLf & vbCrLf & "Nasty _
Message :" ex.Message, "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Cursor.Current = Cursors.Default
End Try End SubIs there anything in particular that I need to do differently
Thanks in advance

Question on Threading...
Cleber Dantas
Worachart
Cosmin Paun
Private Sub MyAddNode()
TreeView1.Nodes.Add New TreeNode("Excel File Creation")
End Sub
And then in your code you can say
BeginInvoke(New MethodInvoker(AddressOf MyAddNode))
Tiago_mor
Andrew Kidd
Here's a bit of the BuildExcelFiles procedure and how the Progressbar is updated. For each file created, the same typical loop is ran.
ProgressBar1.Minimum = 0
for i = 0 to datatable.rows.count - 1ProgressBar1.Maximum = datatable.Rows.Count
ProgressBar1.Value = 0
ProgressBar1.Step = 1
'build my datatable with data for the excel spreadsheet, then open excel object...
cell(i+1,1) = datatable.rows(i).item(0)
cell(i+1,2) = datatable.rows(i).item(1)
'and so on....
ProgressBar1.PerformStep()
next
When I call the BuildExcelFiles, only, in the StartProcess procedure, I get the error message about the control.begininvoke needs to be there, blah blah blah.
Any other thoughts
mikelaw
BeginInvoke(
New MethodInvoker(AddressOf TreeView1.Nodes.Add(New TreeNode("Excel File Creation"))))Anything different about the Treeview
hazzoom
From your snippet (assming that BuildExcelFiles does all the work)
You are executing BuildExcelFiles back on your GUI thread!
BeginInvoke will switch the thread and there is no purpose to your creating a new thread.
You should call BuildExcelFiles directly from StartProcess and only to update the progress bar you would call BeginInvoke
AviF
I think this would be correct VB syntax
New MethodInvoker(AddressOf ProgressBar1.PerformStep)
Michaelxyz3
BeginInvoke(new MethodInvoker(ProgressBar1.PerformStep));