473,804 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cross-thread operation not valid

jamesd0142
469 Contributor
Hi again,

Im using vb 2005

Im using this code to watch a folder and log any changes etc...

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Diagnostics
  3.  
  4.  
  5. Public Class Form1
  6.  
  7.     Public watchfolder As FileSystemWatcher
  8.  
  9.  
  10.     Private Sub btn_startwatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_startwatch.Click
  11.         watchfolder = New System.IO.FileSystemWatcher()
  12.  
  13.         'this is the path we want to monitor
  14.         watchfolder.Path = txt_watchpath.Text
  15.  
  16.         'Add a list of Filter we want to specify
  17.         'make sure you use OR for each Filter as we need to
  18.         'all of those
  19.  
  20.         watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
  21.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  22.                                    IO.NotifyFilters.FileName
  23.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  24.                                    IO.NotifyFilters.Attributes
  25.  
  26.         ' add the handler to each event
  27.         AddHandler watchfolder.Changed, AddressOf logchange
  28.         AddHandler watchfolder.Created, AddressOf logchange
  29.         AddHandler watchfolder.Deleted, AddressOf logchange
  30.  
  31.         ' add the rename handler as the signature is different
  32.         AddHandler watchfolder.Renamed, AddressOf logrename
  33.  
  34.         'Set this property to true to start watching
  35.         watchfolder.EnableRaisingEvents = True
  36.  
  37.         btn_startwatch.Enabled = False
  38.         btn_stop.Enabled = True
  39.  
  40.         'End of code for btn_start_click
  41.  
  42.     End Sub
  43.  
  44.     Private Sub logchange(ByVal source As Object, ByVal e As _
  45.                       System.IO.FileSystemEventArgs)
  46.         If e.ChangeType = IO.WatcherChangeTypes.Changed Then
  47.             txt_folderactivity.Text &= "File " & e.FullPath & _
  48.                                     " has been modified" & vbCrLf
  49.         End If
  50.         If e.ChangeType = IO.WatcherChangeTypes.Created Then
  51.             txt_folderactivity.Text &= "File " & e.FullPath & _
  52.                                     " has been created" & vbCrLf
  53.         End If
  54.         If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
  55.             txt_folderactivity.Text &= "File " & e.FullPath & _
  56.                                     " has been deleted" & vbCrLf
  57.         End If
  58.     End Sub
  59.     Public Sub logrename(ByVal source As Object, ByVal e As _
  60.                          System.IO.RenamedEventArgs)
  61.         txt_folderactivity.Text &= "File" & e.OldName & _
  62.                       " has been renamed to " & e.Name & vbCrLf
  63.     End Sub
  64.  
  65.     Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
  66.         ' Stop watching the folder
  67.         watchfolder.EnableRaisingEvents = False
  68.         btn_startwatch.Enabled = True
  69.         btn_stop.Enabled = False
  70.  
  71.     End Sub
  72. End Class
  73.  
  74.  
I get this error: on line: 47
Expand|Select|Wrap|Line Numbers
  1. Cross-thread operation not valid: Control 'txt_folderactivity' accessed from a thread other than the thread it was created on.
  2.  
Can anyone suggest anything, or tell me what this error means?

James
Feb 28 '08 #1
1 1490
jamesd0142
469 Contributor
Expand|Select|Wrap|Line Numbers
  1. System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false
  2.  
Made the problem go away.

James
Feb 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2055
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
12
3886
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
3
3114
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white rectangles with a big red cross in it. Pressed a button (the one I thought might be ok). My file appeared to load. Then when I clicked on any button on my form, the button was replaced with a white rectangle with a big red cross in it.
0
1897
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
4
5588
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count of defect type by calendar month. Defect types are stored in one table, defect transactions in another along with date etc. When I cross-tab the results, defect types that have no defects recorded against them appear as a blank (null) value. That...
0
2062
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics, manifolds, science, physics, chemistry, law, legal, government, home, office, business, domain lookup, medical, travel, food, university students, searching, searchers, surfing, advanced search, search tools Chemistry, mathematics, physical sciences,...
1
2768
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I have a table containing records for each job done, the records contain date, employee name, job done (a code representing the type of job), cost code (another code), regular hours, and overtime hours. The tricky part is that more than one job can...
6
8638
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have tried, including my conclusions/assumptions (which i'll happily be corrected on if it solves my problem!): The requirement not to use a proxy means I can't use the synchronous
6
5485
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or suggestions are welcome. --
6
3995
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.