By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

Watching for an object to change - ObjectWatcher?

P: n/a
I'd like to use something similar to the FileSystemWatcher to monitor
changes to objects in my own code. Something I can hook bitmaps,
strings, anything to, and have it raise an event when the object is
changed, possibly passing along the new hashcode for the object.

I guess it would be possible to write something like that that checks
the hashcode of an event at a specified interval, but that's a nasty
hack. Isn't there a more elegant way to accomplish this?

I envision something like this:

string myString=null;

objectWatcher.AddWatch(myString);

myString="Hello, world!"; //objWatcher would raise an event here
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> I'd like to use something similar to the FileSystemWatcher to monitor
changes to objects in my own code. Something I can hook bitmaps,
strings, anything to, and have it raise an event when the object is
changed, possibly passing along the new hashcode for the object.

I guess it would be possible to write something like that that checks
the hashcode of an event at a specified interval, but that's a nasty
hack. Isn't there a more elegant way to accomplish this?

I envision something like this:

string myString=null;

objectWatcher.AddWatch(myString);

myString="Hello, world!"; //objWatcher would raise an event here


Assignment doesn't change any object at all.
The only Solution would be to let your objects raise an event if a set
property is called and the value is changed
You can put the event is an interface so you can use if for multiple
classes:

interface IWatchable
{
event EventHandler Changed;
}

class MyClass : IWatchable
{
event EventHandler Changed;

string myProperty;

public string MyProperty
{
set
{
if (value!=myProperty){myProperty=value; Changed(this, new
EventArgs());}
}
}

}

But you cannot use this for predefined classes when you don't inherit from
them.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 16 '05 #2

P: n/a
Hi,

The only way to implement it would be if each object that can be monitorable
include an event for that, otherwise I don't see a clear way of doing what
you want.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"vector" <is****@yahoo.com> wrote in message
news:79**************************@posting.google.c om...
I'd like to use something similar to the FileSystemWatcher to monitor
changes to objects in my own code. Something I can hook bitmaps,
strings, anything to, and have it raise an event when the object is
changed, possibly passing along the new hashcode for the object.

I guess it would be possible to write something like that that checks
the hashcode of an event at a specified interval, but that's a nasty
hack. Isn't there a more elegant way to accomplish this?

I envision something like this:

string myString=null;

objectWatcher.AddWatch(myString);

myString="Hello, world!"; //objWatcher would raise an event here

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.