|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Control.Visble = True ERRORVB.NET 2005 (Express edition) My form contains Statusbar with progressbar and statuslabel Command button At design time the progressbar.Visible = False At runtime I want to make the progressbar.Visble = True and run a method which retrieves data from a "csv" file and populates it to a database. This is triggered in either of two ways, 1 by the commandbutton or 2 by a FileSystemWatcher method which is looking to see if a directory has received a new file. That's the background ..... The Problem? is with the visible property of the progressbar control. Works fine when triggered by the commandbutton but results in an error on that line when triggered by the FileSystemWatcher change event. My code is as follows: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DirectoryWatcher() watcher.EnableRaisingEvents = True End Sub Sub DirectoryWatcher() watcher.Path = ("S:\Mypath") 'watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName) watcher.Filter = "*.csv" AddHandler watcher.Changed, AddressOf OnChanged End Sub Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) PopulateData() End Sub Private Sub PopulateData() ToolStripProgressBar1.Minimum = 0 ToolStripProgressBar1.Maximum = myRecordCount - 1 ToolStripProgressBar1.Value = 0 ToolStripStatusLabel1.Text = "Validating data" ToolStripProgressBar1.Visible = True '......THIS IS THE OFFENDING LINE' Me.Refresh() 'and then a lot more code End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click PopulateData() End Sub and the error reads "Controls created on one thread cannot be parented to a control on a different thread." Anyone know where I'm going wrong Thanks Michael Bond Sounds like the FileSystemWatcher components fires its events on a separate
thread. Try this: Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) If Me.InvokeRequired Then Me.Invoke(New MethodInvoker(AddressOf PopulateData)); Else PopulateData() End If End Sub /claes Show quoteHide quote "mabond" <mab***@discussions.microsoft.com> wrote in message news:1792BF0A-0904-44E4-8D6C-6332BDCBAF9F@microsoft.com... > Hi > > VB.NET 2005 (Express edition) > > My form contains > Statusbar with progressbar and statuslabel > Command button > At design time the progressbar.Visible = False > > At runtime I want to make the progressbar.Visble = True and run a method > which retrieves data from a "csv" file and populates it to a database. > This > is triggered in either of two ways, 1 by the commandbutton or 2 by a > FileSystemWatcher method which is looking to see if a directory has > received > a new file. > > That's the background ..... The Problem? is with the visible property of > the > progressbar control. Works fine when triggered by the commandbutton but > results in an error on that line when triggered by the FileSystemWatcher > change event. > > My code is as follows: > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > DirectoryWatcher() > watcher.EnableRaisingEvents = True > End Sub > > Sub DirectoryWatcher() > watcher.Path = ("S:\Mypath") > 'watcher.NotifyFilter = (NotifyFilters.LastAccess Or > NotifyFilters.LastWrite Or NotifyFilters.FileName Or > NotifyFilters.DirectoryName) > watcher.Filter = "*.csv" > AddHandler watcher.Changed, AddressOf OnChanged > End Sub > > Private Sub OnChanged(ByVal source As Object, ByVal e As > FileSystemEventArgs) > PopulateData() > End Sub > > Private Sub PopulateData() > ToolStripProgressBar1.Minimum = 0 > ToolStripProgressBar1.Maximum = myRecordCount - 1 > ToolStripProgressBar1.Value = 0 > ToolStripStatusLabel1.Text = "Validating data" > ToolStripProgressBar1.Visible = True '......THIS IS THE OFFENDING > LINE' > Me.Refresh() > > 'and then a lot more code > > End Sub > > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button2.Click > PopulateData() > End Sub > > and the error reads > > "Controls created on one thread cannot be parented to a control on a > different thread." > > Anyone know where I'm going wrong > > Thanks > > Michael Bond Claes
Much obliged. That solved the problem. Thanks Michael Bond Show quoteHide quote "Claes Bergefall" wrote: > Sounds like the FileSystemWatcher components fires its events on a separate > thread. Try this: > > Private Sub OnChanged(ByVal source As Object, ByVal e As > FileSystemEventArgs) > If Me.InvokeRequired Then > Me.Invoke(New MethodInvoker(AddressOf PopulateData)); > Else > PopulateData() > End If > End Sub > > /claes > > "mabond" <mab***@discussions.microsoft.com> wrote in message > news:1792BF0A-0904-44E4-8D6C-6332BDCBAF9F@microsoft.com... > > Hi > > > > VB.NET 2005 (Express edition) > > > > My form contains > > Statusbar with progressbar and statuslabel > > Command button > > At design time the progressbar.Visible = False > > > > At runtime I want to make the progressbar.Visble = True and run a method > > which retrieves data from a "csv" file and populates it to a database. > > This > > is triggered in either of two ways, 1 by the commandbutton or 2 by a > > FileSystemWatcher method which is looking to see if a directory has > > received > > a new file. > > > > That's the background ..... The Problem? is with the visible property of > > the > > progressbar control. Works fine when triggered by the commandbutton but > > results in an error on that line when triggered by the FileSystemWatcher > > change event. > > > > My code is as follows: > > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > DirectoryWatcher() > > watcher.EnableRaisingEvents = True > > End Sub > > > > Sub DirectoryWatcher() > > watcher.Path = ("S:\Mypath") > > 'watcher.NotifyFilter = (NotifyFilters.LastAccess Or > > NotifyFilters.LastWrite Or NotifyFilters.FileName Or > > NotifyFilters.DirectoryName) > > watcher.Filter = "*.csv" > > AddHandler watcher.Changed, AddressOf OnChanged > > End Sub > > > > Private Sub OnChanged(ByVal source As Object, ByVal e As > > FileSystemEventArgs) > > PopulateData() > > End Sub > > > > Private Sub PopulateData() > > ToolStripProgressBar1.Minimum = 0 > > ToolStripProgressBar1.Maximum = myRecordCount - 1 > > ToolStripProgressBar1.Value = 0 > > ToolStripStatusLabel1.Text = "Validating data" > > ToolStripProgressBar1.Visible = True '......THIS IS THE OFFENDING > > LINE' > > Me.Refresh() > > > > 'and then a lot more code > > > > End Sub > > > > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button2.Click > > PopulateData() > > End Sub > > > > and the error reads > > > > "Controls created on one thread cannot be parented to a control on a > > different thread." > > > > Anyone know where I'm going wrong > > > > Thanks > > > > Michael Bond > > >
To overload, or not to overload?
ANN: VS.NET 2003 SP1 Memory Usange In VB.NET Serial Port Communuciation in VB with Compact Framework 2.0 Capturing the second column data from a list view box. create a folder useing vb code? Automaticaly Clicking a Checkbox on a webbrowser control hyperlink text client side dataset and dataset DateTime.ParseExact(..) |
|||||||||||||||||||||||