tentavarious
asked on
help invoking actions vb.net
Hello Experts, I created a multithreaded applications using ms visual studio 2008. It almost seems randomly that my program will sit and wait while I am trying to invoke in action. I am not sure if I am using the best method. If i should be using a begininvoke or invoke. Could someone look at my code, i am basically updating some progress bars and labels while the heavy processing is working.
Sub start_progress()
If Me.InvokeRequired Then
Dim dele As Action
dele = AddressOf start_progress
Me.Invoke(dele)
disable_timers(False)
Else
If record_loading_status = False Then
update_cylinder_progress()
ts_main_bar.Style = ProgressBarStyle.Blocks
ts_main_status.Text = "Ready!"
If tsbrefresh.Enabled = False Then
tsbrefresh.Enabled = True
End If
Me.Refresh()
disable_timers(True)
Application.DoEvents()
Else
ora_conn = New OracleConnection("database location")
tsbrefresh.Enabled = False
ts_main_status.Text = "Loading Records"
ts_main_bar.Style = ProgressBarStyle.Marquee
clear_controls(Me)
Me.Refresh()
End If
End If
End Sub
Sub stop_progress()
If Me.InvokeRequired Then
record_loading_status = False
Dim dele As Action
dele = AddressOf start_progress
' Me.Invoke(dele) 'Should i use invoke or begin invoke, it seems like my program locks up here.
Me.BeginInvoke(dele)
End If
End Sub
ASKER
Ok, is there another line of code in which i can check the progress of the begininvoke? And if so can i get an example?
Do you want to know when it is complete?...or something else?
ASKER
yes, when it is complete would be ideal
ASKER
I would like to but it in while loop and check the status, it seems like the begininvoke didnt fix the problem and my program occasionally locks up.
tentavarous,
First my disclaimer: I won't even pretend to be anywhere near Idle_Minds level on this stuff. In fact, he has helped me out many times in the past.
I happen to have a project with a lot of background workers and threads that updates stock prices, candlestick charts and a lot of other dynamic data. Right or wrong, I used the approach of creating Delegates and invoking the delegates where necesarry. It looks like you are doing essentially the same thing, just coded a little differently. Here is a snippet of my code for what it's worth:
First my disclaimer: I won't even pretend to be anywhere near Idle_Minds level on this stuff. In fact, he has helped me out many times in the past.
I happen to have a project with a lot of background workers and threads that updates stock prices, candlestick charts and a lot of other dynamic data. Right or wrong, I used the approach of creating Delegates and invoking the delegates where necesarry. It looks like you are doing essentially the same thing, just coded a little differently. Here is a snippet of my code for what it's worth:
Private Delegate Sub ClearTradeRowsDLG(ByVal myDG As DataGridView)
Public Sub ClearTradeRows(ByVal myDG As DataGridView)
If Me.InvokeRequired Then
Me.Invoke(New ClearTradeRowsDLG(AddressOf ClearTradeRows), New Object() {myDG})
Else
myDG.Rows.Clear()
End If
End Sub
ASKER
I looks like your making a synchronous call back. I thought that may be my problem, so i tried using begininvoke instead, which should create a asynchronous call back. The code below is my latest attempt at getting it to work, not sure if its the correct solution.
Sub stop_progress()
If Me.InvokeRequired Then
Dim result As System.IAsyncResult
Dim dele As Action
dele = AddressOf start_progress
result = Me.BeginInvoke(dele)
Me.EndInvoke(result)
End If
End Sub
ASKER
Ok, my program is still locking up, I put a break on the stop_progress, and sometimes it just waits and nothing happens. I end up having to kill the program. Any idea on what may be causing it to lock?
Sub stop_progress()
If Me.InvokeRequired Then
Dim result As System.IAsyncResult
Dim dele As Action
dele = AddressOf start_progress
result = Me.BeginInvoke(dele)
Me.EndInvoke(result)
End If
end Sub
Sub stop_progress()
If Me.InvokeRequired Then
Dim result As System.IAsyncResult
Dim dele As Action
dele = AddressOf start_progress
result = Me.BeginInvoke(dele)
Me.EndInvoke(result)
End If
end Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If Invoke() is locking up your flow then switch to BeginInvoke().