@@ -23,28 +23,24 @@ public unsafe partial class SystemTrayManager : IDisposable
2323
2424 private HWND _hWnd = default ;
2525 private WNDPROC ? _wndProc ;
26- private bool _isInitialized ;
2726 private uint _dwTaskbarRestartMsgId ;
2827 private bool _isShown ;
2928
30- public void Initialize ( string szWndClassName , string szToolTip , HICON hIcon , Guid id , uint dwCallbackMsgId , Action < uint > callback )
29+ public static SystemTrayManager CreateIcon ( string szWndClassName , string szToolTip , HICON hIcon , Guid id , uint dwCallbackMsgId , Action < uint > callback )
3130 {
32- _szWndClassName = szWndClassName ;
33- _szToolTip = szToolTip ;
34- _hIcon = hIcon ;
35- _id = id ;
36- _dwCallbackMsgId = dwCallbackMsgId ;
37- _callback = callback ;
38-
39- _isInitialized = true ;
31+ return new ( )
32+ {
33+ _szWndClassName = szWndClassName ,
34+ _szToolTip = szToolTip ,
35+ _hIcon = hIcon ,
36+ _id = id ,
37+ _dwCallbackMsgId = dwCallbackMsgId ,
38+ _callback = callback ,
39+ } ;
4040 }
4141
42- public bool CreateIcon ( )
42+ private bool CreateIcon ( )
4343 {
44- // Not expected usage
45- if ( ! _isInitialized )
46- throw new InvalidOperationException ( $ "{ nameof ( SystemTrayManager ) } is not initialized. Call { nameof ( Initialize ) } () before using this method.") ;
47-
4844 if ( _hWnd . IsNull )
4945 _hWnd = CreateIconWindow ( _szWndClassName ) ;
5046
@@ -135,7 +131,7 @@ private LRESULT WndProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
135131
136132 return default ;
137133 }
138- else if ( uMsg == _dwTaskbarRestartMsgId && _isInitialized )
134+ else if ( uMsg == _dwTaskbarRestartMsgId )
139135 {
140136 DeleteIcon ( ) ;
141137 CreateIcon ( ) ;
0 commit comments