473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Control.Visble = True ERROR

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
Aug 16 '06 #1
2 1824
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" <ma****@discussions.microsoft.comwrote in message
news:17**********************************@microsof t.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

Aug 16 '06 #2
Claes

Much obliged. That solved the problem.

Thanks

Michael Bond

"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" <ma****@discussions.microsoft.comwrote in message
news:17**********************************@microsof t.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


Aug 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darryl Kerkeslager | last post by:
The subject says it all (but I'll clarify anyway): I have a form with a tab control. I've added about 12 controls to the form, with those forms within the bounds of the tab, but not on a page, so...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
0
by: Budhi Saputra Prasetya | last post by:
Hi, I still have the same problem with embedding Windows Control. I'll just requote what I posted last time: I managed to create a Windows Form Control and put it on my ASP .NET page. I...
2
by: Matt | last post by:
Hi, I am looking for a control that will allow me to host other controls inside it but have a method of showing and hiding. I have seen plenty of horizontal controls for doing this but I am looking...
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in...
1
by: tshad | last post by:
In VB 2008, I have a user control added to the page in the PageLoad event - but the properties are causing me an error. The program (TakeSurveyTest.aspx) using the control (ContactInfo): <%@...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.