473,406 Members | 2,705 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,406 software developers and data experts.

Strange behaviour when raising an event in FileSystemWatcher eventhandler......


Hi all.

I ran into quite strange problem concerning the event raising inside
FileSystemWatcher Delete event.

First, i would like to describe a bit my environment.

I have main GUI application, which uses other class libraries.
One lib, called Utils.dll contains custom collection implementation.
This simple collection just overrides Add and Remove methods to raise
events whenever item is added or removed from collection.

Another one, called DirStruct.dll, is responsible for watching
filesystem operations in certain directory and update the collection
items to reflect filesystem changes. To achieve that, i used
FileSystemWatcher object and assigned Created/Deleted event handlers.

The collections Add and Remove methods in Utils.dll look like this (more
or less):

protected override void CMyCollection::Add(DMFile file) {
base.Add(file.Name); // Throws an exception if exists
if ( OnFileAdded != null ) {
OnFileAdded(this, file);
}
}

protected override void CMyCollection::Remove(DMFile file) {
if ( base.Remove(file.Name) && OnFileRemoved != null ) {
OnFileRemoved(this, file);
}
}

Here is CMyCollection is inherited from custom template class,
ItemCollection<TValueand ItemCollection inherits from
Dictionary<TKey, TValue>

class CMyCollection : ItemCollection<DMFile>

class ItemCollection<TValue: Dictionary<string, TValuewhere TValue:
KeyItemBase

Kinda messy :)
So far so good. Now, when the DirStruct object receives a filesystem
Create or Delete notification, it calls those methods respectively and
everything works just fine EXCEPT, the Remove method in MY class will
never called. Even though item is removed from collection. On the
contrary, Add method is called normally, OnFileAdded event will be
raised and application GUI will eventually be updated(using Invoke).
When i tried to step into the Remove method in debugger, it never will,
just jumps over. As far as i can see, these two methods in colledction
class should be executed in same context but seems like they don´t. I
know the FileSystemWatcher event handlers are executed in different
thread but it doesn´t matter cause there is no GUI in collection to update.

What i´m missing here?

thanx
Asko.

Oct 31 '06 #1
1 1859

I would suggest saving the result of base.Remove(file.Name) to a local
variable so you can inspect it in the debugger and then be absolutely
sure that it's return true as you suspect.

bool removed = base.Remove(file.Name);
if (removed && OnFileRemoved != null) {
OnFileRemoved(this, file);
}

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Tue, 31 Oct 2006 15:50:14 +0200, Asko Telinen <mr*****@hotmail.com>
wrote:
>
Hi all.

I ran into quite strange problem concerning the event raising inside
FileSystemWatcher Delete event.

protected override void CMyCollection::Remove(DMFile file) {
if ( base.Remove(file.Name) && OnFileRemoved != null ) {
OnFileRemoved(this, file);
}
}
So far so good. Now, when the DirStruct object receives a filesystem
Create or Delete notification, it calls those methods respectively and
everything works just fine EXCEPT, the Remove method in MY class will
never called. Even though item is removed from collection. On the
Oct 31 '06 #2

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

Similar topics

4
by: serge calderara | last post by:
Dear all, I have a class wich is raising events as normally it should do. having a form in the same assembly wich is catching those events works fne. Raise events gets catch normaly within the...
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
0
by: Jeremy Howard | last post by:
Hello everyone, Does anyone know if it is possible to raise an event from a user control contained within an IFRAME and then recieve that event back on the page that contains the IFRAME? Below...
4
by: | last post by:
I have earlier used an HttpModule that did URL rewrites on the BeginRequest event. Now I am trying to use the same module in a different application on a new and upgraded machine (winxp sp2). ...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
4
by: Richard Coltrane | last post by:
Hi there, Im stepping into C# from VB.net. In all the examples ive seen about raising events the following construct is used: if (myevent != null) myevent(this,args); Whats the purpose of...
26
by: buu | last post by:
So, let's say that a user enters an event name in text box, and would like to raise it.. is it possible to call events by their 'name'? Is it possible to enumerate events inside app. and to check...
1
by: Berryl Hesh | last post by:
I am experimenting with a class of widgets, and trying to decide on a general strategy for testing them. Say my button widget has a property in it's interface of: public event EventHandler Click;...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
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...
0
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,...
0
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...

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.