473,748 Members | 8,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange behaviour when raising an event in FileSystemWatch er eventhandler... ...


Hi all.

I ran into quite strange problem concerning the event raising inside
FileSystemWatch er 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
FileSystemWatch er 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.N ame); // Throws an exception if exists
if ( OnFileAdded != null ) {
OnFileAdded(thi s, file);
}
}

protected override void CMyCollection:: Remove(DMFile file) {
if ( base.Remove(fil e.Name) && OnFileRemoved != null ) {
OnFileRemoved(t his, 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<stri ng, 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 FileSystemWatch er 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 1884

I would suggest saving the result of base.Remove(fil e.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(fil e.Name);
if (removed && OnFileRemoved != null) {
OnFileRemoved(t his, 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*****@hotmai l.com>
wrote:
>
Hi all.

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

protected override void CMyCollection:: Remove(DMFile file) {
if ( base.Remove(fil e.Name) && OnFileRemoved != null ) {
OnFileRemoved(t his, 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
2107
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 form and I can process what I want based on them. If I try to catch raised events by this class but within a form located in a different assembly, I am not able to
7
2443
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 Manager. Your main application then hooks into the Plugin Manager. What I'm trying to figure out is how to impliment some form of raising
0
1052
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 is an outline of what I have right now but for some reason the page containing the iframe never updates the textbox that is assigned text in the event handler. MainPage.aspx --> contains an IFRAME --> contains ControlContainer.aspx --> contains...
4
6203
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). The Module is registered via Web.config. The registration is OK. When asking for an existing .aspx page, the eventhandler is called as it should. HOWEVER - if the request url is for a non-existant file, I get a 404 - file
6
2271
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 the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
23
2643
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 EventHandler(); Invoke(d, new object{sender, e}); } else {
4
4642
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 the test for null? Is that testing to see if the underlying delegate is null? If so when would it be?
26
1670
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 their names?
1
1363
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; If I implement this as a Win Forms button, I know I can use the implemented buttons PreformClick() method to test it, but how can I do this more generically, just using the .Net event? For example, in the sample test code below, I think I want...
0
8989
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
8828
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
8241
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...
0
6073
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
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.