V
Vb2Machines
Hello to all,
I have a need to make a progress bar respond while a query is
processing. I looked into the multi threading and I've had mixed results.
I've tried a new thread with no success and I've tried a delegate thread
with limited results. When I use the delegate method and call the
begininvoke I see the progress bar update one time then stop and the query
begins to execute at that time but the progress bar stops updating until the
query is done.
Help please. Here are snippets of the code
Try
RunProgressBar(True)
Application.DoEvents()
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
dsSku = SqlHelper.ExecuteDataset(g_AppParams.OEESqlDbConnString,
CommandType.StoredProcedure, SQL, sqlParam)
Me.Cursor = System.Windows.Forms.Cursors.Default
If Not dsSku.Tables(0).Rows.Count > 0 Then MsgBox("No Data present for
this line or machine for this time period!", MsgBoxStyle.Exclamation)
dgSku.DataSource = dsSku.Tables(0)
RunProgressBar(False)
Catch ex As Exception
Dim oEvent As New cEventLog
oEvent.WriteToEventLog(ex.Message & " -- rdoLastHour_CheckedChanged ",
1111)
End Try
Private Sub RunProgressBar(ByVal BarState As Boolean)
Me.prgFetchData.Visible = True
'Dim t As New Thread(AddressOf UpdateProgressBar) 'Creates the new
thread
'If BarState Then t.Start() Else t.Abort()
Dim td As New TaskDelegate(AddressOf UpdateProgressBar)
If BarState Then td.BeginInvoke(Nothing, Nothing) Else
td.EndInvoke(Nothing) 'Runs on a worker thread from the pool
End Sub
Private Sub UpdateProgressBar()
'Slowly increment the progress bar
Dim i As Integer
For i = 1 To 10
Me.prgFetchData.Value += 10
Thread.CurrentThread.Sleep(500) 'half-second delay
Me.prgFetchData.Refresh()
Next
End Sub
Delegate Sub TaskDelegate()
Am I missing something completely obvious?
thanks in advance,
I have a need to make a progress bar respond while a query is
processing. I looked into the multi threading and I've had mixed results.
I've tried a new thread with no success and I've tried a delegate thread
with limited results. When I use the delegate method and call the
begininvoke I see the progress bar update one time then stop and the query
begins to execute at that time but the progress bar stops updating until the
query is done.
Help please. Here are snippets of the code
Try
RunProgressBar(True)
Application.DoEvents()
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
dsSku = SqlHelper.ExecuteDataset(g_AppParams.OEESqlDbConnString,
CommandType.StoredProcedure, SQL, sqlParam)
Me.Cursor = System.Windows.Forms.Cursors.Default
If Not dsSku.Tables(0).Rows.Count > 0 Then MsgBox("No Data present for
this line or machine for this time period!", MsgBoxStyle.Exclamation)
dgSku.DataSource = dsSku.Tables(0)
RunProgressBar(False)
Catch ex As Exception
Dim oEvent As New cEventLog
oEvent.WriteToEventLog(ex.Message & " -- rdoLastHour_CheckedChanged ",
1111)
End Try
Private Sub RunProgressBar(ByVal BarState As Boolean)
Me.prgFetchData.Visible = True
'Dim t As New Thread(AddressOf UpdateProgressBar) 'Creates the new
thread
'If BarState Then t.Start() Else t.Abort()
Dim td As New TaskDelegate(AddressOf UpdateProgressBar)
If BarState Then td.BeginInvoke(Nothing, Nothing) Else
td.EndInvoke(Nothing) 'Runs on a worker thread from the pool
End Sub
Private Sub UpdateProgressBar()
'Slowly increment the progress bar
Dim i As Integer
For i = 1 To 10
Me.prgFetchData.Value += 10
Thread.CurrentThread.Sleep(500) 'half-second delay
Me.prgFetchData.Refresh()
Next
End Sub
Delegate Sub TaskDelegate()
Am I missing something completely obvious?
thanks in advance,