472,951 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 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 1841

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.