-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NUI] Add WeakEventProxy class and improve invoke of WeakEvent #5424
Conversation
WeakEventProxy는 일반 이벤트를 weak event처럼 사용할 수 있게 proxy 역할을 하는 클래스입니다. 사용할 때는 아래와 같이 derived 클래스를 정의하고, 연결하려는 이벤트를 붙여줘야합니다. class FontSizeChangedWeakEvent : WeakEventProxy<FontSizeChangedEventArgs>
{
protected override void ConnectToEvent(EventHandler<FontSizeChangedEventArgs> handler)
{
SystemSettings.FontSizeChanged += handler;
}
protected override void DisconnectToEvent(EventHandler<FontSizeChangedEventArgs> handler)
{
SystemSettings.FontSizeChanged -= handler;
}
} static FontSizeChangedWeakEvent fontSizeChanged = new FontSizeChangedWeakEvent();
fontSizeChanged.Add((s, e) =>{
// Write handler here
}); |
* WeakEventProxy : The weak event connecting to a normal event. Signed-off-by: Jiyun Yang <[email protected]>
da8f3e9
to
91a491a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
{ | ||
handlers.RemoveAll(item => !item.IsAlive || item.Equals(handler)); | ||
} | ||
|
||
public void Invoke(object sender, EventArgs args) | ||
{ | ||
var copied = handlers.ToArray(); | ||
foreach (var item in copied) | ||
var disposed = new HashSet<WeakHandler<T>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 사용하면 바로 Dispose가 호출되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아뇨. 이 HashSet는 아래 foreach문을 돌때 IsAlive 가 false (이미 GC되어 reference에 닿을 수 없음을 뜻함)인 아이템들을 담기 위해 정의한 것이고 여기 담은 아이템들은 54라인에서 삭제합니다.
Description of Change
API Changes