I have written a program that splits a XML file with it's own class called SplitXML with a SplitFile(). This method has a nested do/while loop that starts at 0 and iterates until the end-of-file. My desire is to access the progress of this loop in another form which will have the progress bar. I could move the SplitFile() into this form with the progress bar, but that would invalidate the class, as I feel I am no longer performing "OOP". I access this class also in a windows service I have created, this SplitXML class appears as "Complete" Object as it is re-usable. I have had a look via Google on Delegates and possibly Multi-Threading but it seems to me that there MUST be an easy way to access the progress of this loop in another form.

Using a progressbar via another class
VikasAgr
I have just google'd your suggestion to generate events and one of the results is
http://www.codeproject.com/csharp/csevents01.asp
It appears then that Delegates are the only way forward. I have run through a simple example below:
using
System;using
System.Collections.Generic;using
System.Text;namespace
ConsoleApplication1{
class Program{
// deleges can be thought of as strongly typed // object oriented function pointers. declaring a delegate // creates a strong type that represents a particular method signature public delegate void PrintMessage(string name); // here I create a couple of methods that match the function // definition above public static void PrintHello(string name){
System.
Console.WriteLine("Hello" + name);}
public static void PrintGoodbye(string name){
System.
Console.WriteLine("Goodbye" + name);}
static void Main(){
/*// to use a delegate you create a new instance of the delegate
// and pass in the method in the constructor, this will be invokes when
// you invoke the delegate
PrintMessage pm = new PrintMessage(PrintHello);
pm("World");
pm = new PrintMessage(PrintGoodbye);
pm("World");*/
PrintMessage pm = new PrintMessage(PrintHello);pm +=
new PrintMessage(PrintGoodbye);pm(
"Champ");}
}
}
I grasp the fact that you are passing in a method instead of a string (above). I fear though, that there must be some fundamental nuance in what is happening that I'm missing, hence am unable to use this "applied knowledge" to resolve my problem. Most tutorials indicate that delegates are rather tricky to grasp first hand so this must be my problem. I learn't to program in c++ and understand the fact that you are pointing to a memory address with a value in it (the heap as oppossed to the stack in .NET). I presume then that as I iterate an event is raised upon each iteration, that passes a "value", (the increment of the file size, possible as an int). How do I tie this all together
James CACN
Hi
There is one way to resolve that problem:
// SplitXML class
// Form with progressbar
Hope this help.
Yours Markku
Bluehunter
Just what the doctor ordered. The difficulty I had was tying the "event" to the "delegate", this example also goes someway to appreciating how all the events I so frequently use actually work.
Thank you!
TexMatt
And then implement an eventhandler for the SplitXml events in your form (which updates the progressbar).