.NET Framework 2.0에서 AutoResetEvent 및 ManualResetEvent는 EventWaitHandle에서 상속됩니다. EventWaitHandle 클래스에는 4 개의 다른 생성자가 있습니다. 생성자 중 3 명은 이벤트에 이름을 부여하는 것을 지원합니다. 반면에 ManualResetEvent와 AutoResetEvent는 모두 이름 지정을 지원하지 않으며 initialState를받는 단일 생성자를 제공합니다. EventWaitHandle에서 상속받을 수 있고 모든 생성자 오버로드를 지원하는 클래스를 직접 구현할 수도 있지만 필자는 그렇게하지 않으면 휠을 다시 발명하고 싶지 않습니다. 내 질문 :AutoResetEvent 및 ManualResetEvent가 생성자에서 이름을 지원하지 않는 이유는 무엇입니까?
- 이벤트 이름 지정에 특별한 문제가 있습니까?
- Microsoft에서 왜 지원하지 않았는지 알고 계십니까?
- 다음 예제와 같이 EventWaitHandle 클래스에서 상속 받고 적절한 생성자를 호출하는 것이 좋습니다.
public class MyAutoResetEvent: EventWaitHandle { public MyAutoResetEvent(bool initialState) : base(initialState, EventResetMode.AutoReset) { } public MyAutoResetEvent(bool initialState, string name) : base(initialState, EventResetMode.AutoReset, name) { } public MyAutoResetEvent(bool initialState, string name, out bool createdNew) : base(initialState, EventResetMode.AutoReset, name, out createdNew) { } public MyAutoResetEvent(bool initialState, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity) : base(initialState, EventResetMode.AutoReset, string.Empty, out createdNew, eventSecurity) { } }
귀하의 솔루션은 제 솔루션과 유사합니다. 파생 클래스 생성자에서 EventWaitHandle을 호출하고이를 직접 사용합니다. – Ikaso
@ lkaso 파생 클래스를 만드는 것보다 조금 더 똑바로 생각했습니다 ... 불행히도 설계 선택의 이유에 관해서는 많이 제공하지 않습니다. – Kiril