更新调用UI函数DLL
我试图弄清楚如何从正在执行某些任务的 DLL 更新我的 UI。
我不明白 DLL 如何知道 UI 的任何信息。
希望能解释得更清楚:
我有任务 1、任务 2 和 UI。
task1 和task2 都是DLL,对UI 不了解。
我如何告诉 DLL 调用 UI 中的某些函数?
希望我足够清楚,我对 C# 的了解还远远没有达到我想要的水平。
提前致谢。
PS 希望不会让事情变得更糟 这两个任务都有自己的 appDomain
I am trying to figure out how I can update my UI from an DLL that is doing some task.
I cant figure out how the DLL can know anything of the UI.
To hopefully explain more clear:
I have let's say task1, task2 and UI.
task1 and task2 are both DLL's and dont know anything of UI.
How can I tell the DLL's to call some function in UI?
Hopefully I am clear enough, my knowledge of C# is far from where I want it to be.
Thanks in advance.
PS to hopefully not make it worse both tasks have their own appDomain's
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会告诉他们更新 UI,您会引发一个事件来指示某些内容已发生更改,这可能很有趣 - 然后您使 UI 在您的实例上订阅该事件,并相应地更新 UI。
因此,假设您希望在类上的任何属性发生更改时引发一个事件(方便的是,有 INotifyPropertyChanged 接口,它甚至描述了您将要执行此操作,以及很多事情会“注意到”并“做正确的事情”,例如
BindingList
)因此,您声明您的类具有属性:
然后,要引发事件,您只需调用:
订阅事件(在您的客户端应用程序/UI 层)就像拥有事件处理程序一样简单:
添加接线
You don't tell them to update the UI, you raise an event that indicates something has changed, that might be interesting - you then make the UI subscribe to that event on your instances, and update the UI accordingly.
So, let's say you want to raise an event whenever any of the properties on a class change (conveniently, there is the
INotifyPropertyChanged
interface that even describes that you are going to do this, and a lot of things will "notice" and "do the right thing", such asBindingList<T>
)So you declare that your class has properties:
Then, to raise the event, you simply call:
To subscribe to the events (in your client application/UI layer) it's as simple as having your event hadler:
Add wiring up