I have created a class that handles encrypted database traffic. I have used external Event definitions successfully, allowing the calling process to properly handle errors that - while they occurred within the database module - actually originated from the calling procedure.
Using the external Error handler I would do the following:
public event EventHandler ErrorStatusChanged;
...and later, if/when such occurred, I would handle it like this:
if (ErrorStatusChanged != null)
{
ErrorStatusChanged(this, EventArgs.Empty);
}
...and that seems to work just fine. However, now I want to extend further using a callback function, but I have only a few clues how I might approach this situation. (I feel sure that it is possible to accomplish this, but I'm fairly lost/confused as to actual implementation...)
Something like:
public delegate void Update_System_Status (bool dbConnected, string textStatus);
...and then later (I'm sure I've got this wrong, the compiler flags it even before compile time):
if (Update_System_Status != null)
{
Update_System_Status(bConnFlag, sConnTextStatus);
}
I'd like to build a couple of callbacks - one that allows the datahandler class to inform the calling process that it has successfully connected (or not), and another to handle updating a progress bar during the longer mass-update processes. And after numerous searches using [callback] and/or [delegate] as keywords, I'm getting nowhere quickly. I am, however, getting really confused!
I had envisioned that I would provide some sort of interface, very similar to the EventHander (above) and be able to determine - later on, when it is needed - whether the calling procedure provided the proper function, and call it if/when possible. I know that not all programmers will want to provide a main form update callback function to this database handler, so I figure I'll need to somehow "know" when one has been provided, and when not.
I have unsuccessfully employed the [delegate] keyword, and have no idea how to use the [interface] directive at all - all of the examples I keep running into illustrate the functions being internal to the class, which is exactly not what I am trying to achieve. I am trying to provide a framework that will allow an external process to provide a function that, when something happens inside the class/object that would be good to update the external (calling) system, could do so by calling the provided function (from outside).
Thanks (in advance) for your assistance - I'm lost!