I am building a .NET solution with a GUI mode(one project) and a console mode (another project). Each of these projects references a shared class library that holds the shared logical guts behind each app. I want the DLL to be as isolated as possible from each client application. how can I have the DLL report progress to the gui? Right now, the GUI project references the DLL. VS2010 / .NET won’t let me reference the GUI from the DLL because it would be a circular reference.
How can I do this? Are there any general principles for how to handle this in .NET design, or software design in general? Is there a way to use a callback without a reference to the calling project?
It sounds to me like you need a custom event in your DLL that you then attach to in your GUI.
Here’s some code to make it more understandable.
First off lets create a mock of our DLL that does something similar to loading and also defines an event we can attach to in our GUI that received the completed percentage:
Now we have a mock DLL that exposes a
StatusChangedevent for our GUI to hook into. Here’s a mock GUI taking advantage of this:and Bingo, our GUI is receiving the complete percentage from the DLL without the DLL needing to know anything about the GUI.
The CustomEventArgs I used above looks like this: