Search code examples
c#wpfuser-interfacesystem.componentmodel

Updating WPF GUI from a DLL


This seems like it would be pretty common task, but I'm not having any luck searching for an answer.

I have a WPF/C# application that relies heavily on a dll for database routines. I would like the dll to update some GUI elements, i.e. a progress bar.

So far, it seems that the answer lies somewhere in System.ComponentModel and creating a backgroundworker. But that's as far as I can get.

Can someone please offer suggestions on how to accomplish this task? Links, sample code, encouraging words appreciated!

Many thanks,

Jerry


Solution

  • Your best bet is to set it up so that the UI passes in a callback function when calling into the database DLL. The database DLL calls that callback "periodically", and the callback implemented in the UI then updates the UI elements.

    It would be best not to let your database DLL muck around with your UI. For one thing, it would make the DLL very dependent upon the specifics of your UI, to the point that the DLL would not really be usable by any other exe.