Is it appropriate to store all forms and threads inside a custom ApplicationContext class?
I'm trying to figure out a way to divide the UI from the business logic. In addition, I want the business logic to be able to notify the UI of updates easily without having to pass a reference to a form all over t开发者_Python百科he business logic or something like that. I found the ApplicationContext class and it seems like it would allow me to store all forms and threads in a higher level class. It just seems odd that the main form contains handles to different threads and other forms. Is it appropriate to put all of this in ApplicationContext? I was thinking about making it a singleton as well so that the business logic can easily notify the UI. Thanks!
For what you are trying to do, consider using a BackgroundWorker
. The BackgroundWorker will use your threads properly, and provides ways to safely pass status information back to the UI.
If you want your business logic to notify your interface, you shouldn't pass a reference to the UI objects, instead use events or callbacks that the UI can handle to be notified by events.
精彩评论