![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Form Refesh not working under Threading If I call the "SyncTables" Sub without a Thread all the code works fine and with the Thread I'm not getting any errors but the ProgressBar & Label referenced in the last "Class SyncChartofAcc" no longer updates on the Refesh. I removed all the Progress loops to simplify the code. Thanks in advance John Public Class WebTimer Private WithEvents myBackgroundWorker As New System.ComponentModel.BackgroundWorker Private Delegate Sub ProgressHandler() Dim updateHandler As ProgressHandler = Nothing Private Sub btnSync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSync.Click Dim t As Thread t = New Thread(AddressOf SyncTables) t.Start() End Sub Private Sub DoWork() pgbSync.Step = 8 pgbSync.PerformStep() End Sub Private Sub SyncTables() pgbSync.Maximum = 100 updateHandler = New ProgressHandler(AddressOf DoWork) 'Call Class Dim SyncChart As New SyncChartOfAcc SyncChart.DoAccountQueryRq("US", 5, 0, O, qbFileLoc, CompID) 'This Progress update is working under Thread If pgbSync.InvokeRequired Then Invoke(updateHandler) Else pgbSync.PerformStep() End If End Sub End Class Public Class SyncChartOfAcc Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion As Short, ByVal minorVersion As Short _ , ByVal O As Integer, ByVal qbFileLoc As String, ByVal CompID As String) 'This Progress update is not working under Thread Dim prg As ProgressBar = WebTimer.pgbSegmentSync Dim lblProg As Label = WebTimer.lblSyncSegPrg prg.Maximum = 100 prg.Step = 1 lblProg.Text = "Getting Chart of Accounts" WebTimer.Refresh() 'loops removed to simplify prg.PerformStep() lblProg.Text = "Processing Account Number " & (QBList.Count) - c WebTimer.Refresh() End Sub End Class |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Form Refesh not working under Threading Yes I stepped thru the code and tried adding a new Instance also and still no error, but no Refresh on the WebTimer form either. I tested for InvokeRequired and it returns false. These are my Imports Imports System.Threading Imports System.Configuration Thanks John "Family Tree Mike" <FTM@xxxxxx> wrote in message news F69663A-3DED-45D2-AE54-B13D110A0339@xxxxxxQuote: > "John" <non@xxxxxx> wrote in message > news:OVpKq0ikJHA.4880@xxxxxx Quote: >> >> Public Class SyncChartOfAcc >> Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion >> As Short, ByVal minorVersion As Short _ >> , ByVal O As Integer, ByVal qbFileLoc As >> String, ByVal CompID As String) >> >> 'This Progress update is not working under Thread >> Dim prg As ProgressBar = WebTimer.pgbSegmentSync >> Dim lblProg As Label = WebTimer.lblSyncSegPrg > WebTimer is a class, not an object. Does this really work? > > When I changed the code to what I think this should be, adding an instance > of the WebTimer class in the class SyncChartOfAcc, I get a cross thread > error, which I would expect. > > > -- > Mike > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Form Refesh not working under Threading John, You cannot reach any UI from a worker thread, you need to make some communication to your main thread. Cor "John" <non@xxxxxx> wrote in message news:OVpKq0ikJHA.4880@xxxxxx Quote: > If I call the "SyncTables" Sub without a Thread all the code works fine > and with the Thread I'm not getting any errors but the ProgressBar & Label > referenced > in the last "Class SyncChartofAcc" no longer updates on the Refesh. I > removed all the Progress loops to simplify the code. > Thanks in advance > John > > Public Class WebTimer > > Private WithEvents myBackgroundWorker As New > System.ComponentModel.BackgroundWorker > Private Delegate Sub ProgressHandler() > Dim updateHandler As ProgressHandler = Nothing > > Private Sub btnSync_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles btnSync.Click > > Dim t As Thread > t = New Thread(AddressOf SyncTables) > t.Start() > > End Sub > > > > Private Sub DoWork() > pgbSync.Step = 8 > pgbSync.PerformStep() > > End Sub > > > > Private Sub SyncTables() > > pgbSync.Maximum = 100 > updateHandler = New ProgressHandler(AddressOf DoWork) > > 'Call Class > Dim SyncChart As New SyncChartOfAcc > SyncChart.DoAccountQueryRq("US", 5, 0, O, qbFileLoc, CompID) > > 'This Progress update is working under Thread > If pgbSync.InvokeRequired Then > Invoke(updateHandler) > Else > pgbSync.PerformStep() > End If > > End Sub > > End Class > > > > Public Class SyncChartOfAcc > Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion As > Short, ByVal minorVersion As Short _ > , ByVal O As Integer, ByVal qbFileLoc As > String, ByVal CompID As String) > > 'This Progress update is not working under Thread > Dim prg As ProgressBar = WebTimer.pgbSegmentSync > Dim lblProg As Label = WebTimer.lblSyncSegPrg > prg.Maximum = 100 > prg.Step = 1 > lblProg.Text = "Getting Chart of Accounts" > WebTimer.Refresh() > > > 'loops removed to simplify > prg.PerformStep() > lblProg.Text = "Processing Account Number " & (QBList.Count) - c > WebTimer.Refresh() > > > End Sub > > End Class > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Form Refesh not working under Threading I added a WebTmer.Show to see what happens, it opens a 2nd instance of the Form, which does show an active progressbar, it then closes when the code is done leaving the original WebTimer Form. just relating what I find John "Family Tree Mike" <FTM@xxxxxx> wrote in message news F69663A-3DED-45D2-AE54-B13D110A0339@xxxxxxQuote: > "John" <non@xxxxxx> wrote in message > news:OVpKq0ikJHA.4880@xxxxxx Quote: >> >> Public Class SyncChartOfAcc >> Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion >> As Short, ByVal minorVersion As Short _ >> , ByVal O As Integer, ByVal qbFileLoc As >> String, ByVal CompID As String) >> >> 'This Progress update is not working under Thread >> Dim prg As ProgressBar = WebTimer.pgbSegmentSync >> Dim lblProg As Label = WebTimer.lblSyncSegPrg > WebTimer is a class, not an object. Does this really work? > > When I changed the code to what I think this should be, adding an instance > of the WebTimer class in the class SyncChartOfAcc, I get a cross thread > error, which I would expect. > > > -- > Mike > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Form Refesh not working under Threading Thanks I just started to replicate what is working on the first Progress with the New Thread doing just what you are saying, this is what I got so far but getting a: Invoke cannot be called on a control until a Window Handle has been created 'Call back to main thread Dim webT As New WebTimer webT.ProgressSync() 'Main thread Public Sub ProgressSync() updateHandler = New ProgressHandler(AddressOf DoWorkSync1) 'getting windows Handle error next line Invoke(updateHandler) End Sub Private Sub DoWorkSync1() pgbSegmentSync.Maximum = 100 pgbSegmentSync.Step = 1 pgbSegmentSync.PerformStep() lblSyncSegPrg.Text = "Getting Chart of Accounts" End Sub "Cor Ligthert[MVP]" <Notmyfirstname@xxxxxx> wrote in message news:OsRwn$mkJHA.1288@xxxxxx Quote: > John, > > You cannot reach any UI from a worker thread, you need to make some > communication to your main thread. > > Cor > > "John" <non@xxxxxx> wrote in message > news:OVpKq0ikJHA.4880@xxxxxx Quote: >> If I call the "SyncTables" Sub without a Thread all the code works fine >> and with the Thread I'm not getting any errors but the ProgressBar & >> Label referenced >> in the last "Class SyncChartofAcc" no longer updates on the Refesh. I >> removed all the Progress loops to simplify the code. >> Thanks in advance >> John >> >> Public Class WebTimer >> >> Private WithEvents myBackgroundWorker As New >> System.ComponentModel.BackgroundWorker >> Private Delegate Sub ProgressHandler() >> Dim updateHandler As ProgressHandler = Nothing >> >> Private Sub btnSync_Click(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles btnSync.Click >> >> Dim t As Thread >> t = New Thread(AddressOf SyncTables) >> t.Start() >> >> End Sub >> >> >> >> Private Sub DoWork() >> pgbSync.Step = 8 >> pgbSync.PerformStep() >> >> End Sub >> >> >> >> Private Sub SyncTables() >> >> pgbSync.Maximum = 100 >> updateHandler = New ProgressHandler(AddressOf DoWork) >> >> 'Call Class >> Dim SyncChart As New SyncChartOfAcc >> SyncChart.DoAccountQueryRq("US", 5, 0, O, qbFileLoc, CompID) >> >> 'This Progress update is working under Thread >> If pgbSync.InvokeRequired Then >> Invoke(updateHandler) >> Else >> pgbSync.PerformStep() >> End If >> >> End Sub >> >> End Class >> >> >> >> Public Class SyncChartOfAcc >> Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion >> As Short, ByVal minorVersion As Short _ >> , ByVal O As Integer, ByVal qbFileLoc As >> String, ByVal CompID As String) >> >> 'This Progress update is not working under Thread >> Dim prg As ProgressBar = WebTimer.pgbSegmentSync >> Dim lblProg As Label = WebTimer.lblSyncSegPrg >> prg.Maximum = 100 >> prg.Step = 1 >> lblProg.Text = "Getting Chart of Accounts" >> WebTimer.Refresh() >> >> >> 'loops removed to simplify >> prg.PerformStep() >> lblProg.Text = "Processing Account Number " & (QBList.Count) - c >> WebTimer.Refresh() >> >> >> End Sub >> >> End Class >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Form Refesh not working under Threading Worked great thanks for your help John "Family Tree Mike" <FTM@xxxxxx> wrote in message news:6A2708C0-16E9-42B6-85F1-EE8A6B3F5CA7@xxxxxx Quote: > "John" <non@xxxxxx> wrote in message > news:u9$2gzmkJHA.4912@xxxxxx Quote: >> Yes I stepped thru the code and tried adding a new Instance also and >> still no error, but no Refresh on the WebTimer form either. >> >> I tested for InvokeRequired and it returns false. >> These are my Imports >> Imports System.Threading >> Imports System.Configuration >> >> Thanks >> John >> >> "Family Tree Mike" <FTM@xxxxxx> wrote in message >> news F69663A-3DED-45D2-AE54-B13D110A0339@xxxxxxQuote: >>> "John" <non@xxxxxx> wrote in message >>> news:OVpKq0ikJHA.4880@xxxxxx >>>> >>>> Public Class SyncChartOfAcc >>>> Public Sub DoAccountQueryRq(ByVal country As String, ByVal majorVersion >>>> As Short, ByVal minorVersion As Short _ >>>> , ByVal O As Integer, ByVal qbFileLoc As >>>> String, ByVal CompID As String) >>>> >>>> 'This Progress update is not working under Thread >>>> Dim prg As ProgressBar = WebTimer.pgbSegmentSync >>>> Dim lblProg As Label = WebTimer.lblSyncSegPrg >>> >>> WebTimer is a class, not an object. Does this really work? >>> >>> When I changed the code to what I think this should be, adding an >>> instance of the WebTimer class in the class SyncChartOfAcc, I get a >>> cross thread error, which I would expect. >>> >>> >>> -- >>> Mike >>> >> > > Don't add a new instance, but instead pass the current instance of the > WebTimer to your SyncChartOfAcc instance in sub SyncTables. > > Something like: > > dim SyncChart as new SyncChartOfAcc > SyncChart.WT = Me > > then in SyncChartOfAcc: > > public WT as WebTimer ' better to use a property than a field. > > and then in DoAccountQueryRq use WT rather than WebTimer. > > > -- > Mike > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Threading problem | .NET General | |||
| Threading Disappeared... | Live Mail | |||
| Threading problem | .NET General | |||
| E-mail: threading | Live Mail | |||
| Strict Threading | Vista mail | |||