473,569 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Source of Additional Thread(s)?

Does the FileSystemWatch er class, when enabled, spawn a new thread for
itself?

I googled and somehow just found people having random problems with the
FileSystemWatch er class and the MSDN docs. MSDN online didn't clarify (at
least not that I found).

My situation is that I have a Windows Forms app. The application class hosts
a singleton instance of another class. That other class communicates with
the hosting app primarily via events (that it, the singleton, raises). One
of the tasks of the singleton is to spawn a few FileSystemWatch er instances
that monitor a few directories for changes. The FileSystemWatch er events are
handled within the singleton, which, upon certain types of changes turns
around and raises a brand new event which is then handled by the hosting
application - which, in turn, updates UI controls.

When events are raised from the hosted singleton that have nothing to do
with the FileSystemWatch er instances, then the hosting app updates the UI
controls just fine.
But when events are raised from the hosted singleton that are raised from
the FileSystemWatch er event handling methods (within the singleton), then
the hosting application chokes when it goes to update UI controls.
Specifically VS gives me "Cross-thread operation not valid: Control 'xyz'
accessed from a thread other than the thread it was created on."

I believe I do understand the threading issues going on here, and I have
been able to remediate. What I would appreciate a bit of clarification on is
this: Where did the other thread(s) come from? I have not explicitly
launched any additional threads. My suspicion is that the FileSystemWatch er
instances create their own background threads. Is that true? If not, then
what would be a likely source of the additional thread(s) given that I'm not
explicitly creating any.

Thanks!
Aug 15 '07 #1
4 1695
Yes, using the reflector i found the code using the thread, also think
logiclly, the file system watcher proopose is to notify the application on
file changed, this must be in diffrent thread.

Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Smithers" wrote:
Does the FileSystemWatch er class, when enabled, spawn a new thread for
itself?

I googled and somehow just found people having random problems with the
FileSystemWatch er class and the MSDN docs. MSDN online didn't clarify (at
least not that I found).

My situation is that I have a Windows Forms app. The application class hosts
a singleton instance of another class. That other class communicates with
the hosting app primarily via events (that it, the singleton, raises). One
of the tasks of the singleton is to spawn a few FileSystemWatch er instances
that monitor a few directories for changes. The FileSystemWatch er events are
handled within the singleton, which, upon certain types of changes turns
around and raises a brand new event which is then handled by the hosting
application - which, in turn, updates UI controls.

When events are raised from the hosted singleton that have nothing to do
with the FileSystemWatch er instances, then the hosting app updates the UI
controls just fine.
But when events are raised from the hosted singleton that are raised from
the FileSystemWatch er event handling methods (within the singleton), then
the hosting application chokes when it goes to update UI controls.
Specifically VS gives me "Cross-thread operation not valid: Control 'xyz'
accessed from a thread other than the thread it was created on."

I believe I do understand the threading issues going on here, and I have
been able to remediate. What I would appreciate a bit of clarification on is
this: Where did the other thread(s) come from? I have not explicitly
launched any additional threads. My suspicion is that the FileSystemWatch er
instances create their own background threads. Is that true? If not, then
what would be a likely source of the additional thread(s) given that I'm not
explicitly creating any.

Thanks!
Aug 15 '07 #2
Also when lookiong on msdn example you can see that no thread should be
queued for the file notify changed, so it use it internally
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Smithers" wrote:
Does the FileSystemWatch er class, when enabled, spawn a new thread for
itself?

I googled and somehow just found people having random problems with the
FileSystemWatch er class and the MSDN docs. MSDN online didn't clarify (at
least not that I found).

My situation is that I have a Windows Forms app. The application class hosts
a singleton instance of another class. That other class communicates with
the hosting app primarily via events (that it, the singleton, raises). One
of the tasks of the singleton is to spawn a few FileSystemWatch er instances
that monitor a few directories for changes. The FileSystemWatch er events are
handled within the singleton, which, upon certain types of changes turns
around and raises a brand new event which is then handled by the hosting
application - which, in turn, updates UI controls.

When events are raised from the hosted singleton that have nothing to do
with the FileSystemWatch er instances, then the hosting app updates the UI
controls just fine.
But when events are raised from the hosted singleton that are raised from
the FileSystemWatch er event handling methods (within the singleton), then
the hosting application chokes when it goes to update UI controls.
Specifically VS gives me "Cross-thread operation not valid: Control 'xyz'
accessed from a thread other than the thread it was created on."

I believe I do understand the threading issues going on here, and I have
been able to remediate. What I would appreciate a bit of clarification on is
this: Where did the other thread(s) come from? I have not explicitly
launched any additional threads. My suspicion is that the FileSystemWatch er
instances create their own background threads. Is that true? If not, then
what would be a likely source of the additional thread(s) given that I'm not
explicitly creating any.

Thanks!
Aug 15 '07 #3
Smithers <A@B.comwrote :

<snip>
I believe I do understand the threading issues going on here, and I have
been able to remediate. What I would appreciate a bit of clarification on is
this: Where did the other thread(s) come from? I have not explicitly
launched any additional threads. My suspicion is that the FileSystemWatch er
instances create their own background threads. Is that true? If not, then
what would be a likely source of the additional thread(s) given that I'm not
explicitly creating any.
From the docs of FileSystemWatch er.Synchronizin gObject:

<quote>
When SynchronizingOb ject is a null reference (Nothing in Visual Basic),
methods handling the Changed, Created, Deleted, and Renamed events are
called on a thread from the system thread pool. For more information on
system thread pools, see ThreadPool.

When the Changed, Created, Deleted, and Renamed events are handled by a
visual Windows Forms component, such as a Button, accessing the
component through the system thread pool might not work, or may result
in an exception. Avoid this by setting SynchronizingOb ject to a Windows
Forms component, which causes the methods that handle the Changed,
Created, Deleted, and Renamed events to be called on the same thread on
which the component was created.
</quote>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 15 '07 #4
Well it couldn't be more perfectly clear. I guess I'll be more patient with
the MSDN docs next time. Thanks for the quote.

-S

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Smithers <A@B.comwrote :

<snip>
>I believe I do understand the threading issues going on here, and I have
been able to remediate. What I would appreciate a bit of clarification on
is
this: Where did the other thread(s) come from? I have not explicitly
launched any additional threads. My suspicion is that the
FileSystemWatc her
instances create their own background threads. Is that true? If not, then
what would be a likely source of the additional thread(s) given that I'm
not
explicitly creating any.

From the docs of FileSystemWatch er.Synchronizin gObject:

<quote>
When SynchronizingOb ject is a null reference (Nothing in Visual Basic),
methods handling the Changed, Created, Deleted, and Renamed events are
called on a thread from the system thread pool. For more information on
system thread pools, see ThreadPool.

When the Changed, Created, Deleted, and Renamed events are handled by a
visual Windows Forms component, such as a Button, accessing the
component through the system thread pool might not work, or may result
in an exception. Avoid this by setting SynchronizingOb ject to a Windows
Forms component, which causes the methods that handle the Changed,
Created, Deleted, and Renamed events to be called on the same thread on
which the component was created.
</quote>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 15 '07 #5

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

Similar topics

27
2575
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not in the changes document? John Roth
188
8298
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python 2.4 installer for windows. Now I have problems to compile python extension that some packages
2
4938
by: markusszil | last post by:
Hello all, I am working on an application which uses quite a few bitmaps as skins for custom controls. I am getting a very difficult bug to track - my application performs quite a few bitmap operations which use a timer to help time-slice so the UI remains responsive. At one point, I am setting a flag to indicate to the timer that a...
15
3369
by: Enzo | last post by:
Hi Ng, It's possible to protect the source code of a js file? With PHP? Thanks in advance! Enzo
29
2755
by: Frank Millman | last post by:
Hi all I am writing a multi-user accounting/business system. Data is stored in a database (PostgreSQL on Linux, SQL Server on Windows). I have written a Python program to run on the client, which uses wxPython as a gui, and connects to the database via TCP/IP. The client program contains all the authentication and business logic. It has...
4
2023
by: thiamwah | last post by:
Hi, I have a SQL statement that access to one database (DB2) i.e. SELECT DB1.TABLE1.TABLE1_ID, DB1.TABLE1.FIELD_A, DB1.TABLE2.FIELD_1, DB1.TABLE2.FIELD_2,
115
14005
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i prefer a solution that (also) supports Windows. On the net I found a number of products that i looked at, but none of them gave me the impression...
7
10042
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works great, at least on my system. The reason I am doing this is some customers are pulling from VPN connections which are slow. This allows the list of...
2
1120
by: Michel Vanderbeke | last post by:
Hello, When you get an error in a VB.NET program, is it possible to know what is the origin of the error. I assume it can be VB.NET, the framework, a database engine, the database itself (Access, SQL Server, ...). How can you know which source has thrown the exception? Some error messages are in English, some in my own language. Many...
0
7703
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...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
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...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2117
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
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
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...

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.