views:

50

answers:

4

I created this simple textpad program in WPF/VB.NET 2008 that automatically saves the content of the forms to an XML file on every keystroke.

Now, I'm trying to make the program see the changes on the XML file in realtime.. example, If I open two of my textpads, when I write on the first one, it will automatically reflect on the other textpad.

How can I do this?

One of my colleagues told me to read about iNotifyPropertyChanged (which I did) but how can I apply it to my application..?

:( help~

btw, I got the idea from a Google Wave demo, and I'm actually trying to do something bigger..

A: 

You will probably need to use the FileSystemWatcher to watch the file on the disk rather than a property in the running instance of the application.

Or you could use some custom message passing between different instances of your application.

benPearce
A: 

INotifyPropertyChanged isn't going to work for your application. That interfaced is used when data binding some element to a UI object.

Your best bet is going to be to attach a FileSystemWatcher to the file when you open it for editing. You can then use the change events to reload the file as needed in each instance of your application.

This will also load changes made from external editors.

Justin Niessner
+1  A: 

Note - this approach will be really, really expensive in terms of disk I/O, memory usage and CPU time. Why are you using XML is that the native format of the data you are editing? You may want to look at a more compact format - one that will use less memory, generate fewer I/Os and use less CPU.

Also note that you writer may need to flush the file for the watcher to notice any changes. This is expensive as well - especially if you re doing it on every key stroke.

Be sure to use the correct file open attributes (sharing, reading and writing).

You may want to consider using shared memory to communicate between your processes. This will be less expensive. You can avoid large ammounts of disk I/O by only writing changes to disk when the use asks to commit them, or there is a hint to do so. I suggest avoiding doing this on every key stroke.

Remember, your app needs to be a good system citizen and consume a reasonable amount of system resources. This is especially true running on netbooks and other 'low spec' systems.

Foredecker
Where can I start reading about "Shared Memory" on VB.Net? It sounds more 'at-home' on C#, which I don't have that much experience on..
GaiusSensei
A: 

It sounds like you are using file IO as a form of interprocess communication, if so, IMO you need to rethink your design, especially if you are doing something "bigger" than google wave (whatever bigger means in this context) as what you are proposing is terribly ineficient.

Do some searching on Interprocess communication and you will get a whole bunch of idea's @foredecker's idea (+1) of shared memory is a good possibility for example.

Tim Jarvis