File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -20,27 +20,27 @@ public static bool First(string globalName = null)
2020
2121 try
2222 {
23- mmf = MemoryMappedFile . OpenExisting ( globalName ) ;
24- using ( var r = mmf . CreateViewAccessor ( ) )
25- {
26- r . Read ( 0 , out long value ) ;
27- messageHandle = new IntPtr ( value ) ;
28-
29- return false ;
30- }
31- }
32- catch ( FileNotFoundException )
33- {
23+ mmf = MemoryMappedFile . CreateNew ( globalName , 8 ) ;
3424 messageWindow = new HwndSource ( new HwndSourceParameters ( ) ) ;
3525 ChangeWindowMessageFilterEx ( messageWindow . Handle , WM_COPYDATA , 1 , IntPtr . Zero ) ;
36- mmf = MemoryMappedFile . CreateNew ( globalName , 8 ) ;
3726 using ( var w = mmf . CreateViewAccessor ( ) )
3827 w . Write ( 0 , ( long ) messageWindow . Handle ) ;
3928
4029 messageWindow . AddHook ( WndProc ) ;
4130
4231 return true ;
4332 }
33+ catch ( IOException e ) when ( ( uint ) e . HResult == 0x800700B7 ) // already exists
34+ {
35+ mmf = MemoryMappedFile . OpenExisting ( globalName ) ;
36+ using ( var r = mmf . CreateViewAccessor ( ) )
37+ {
38+ r . Read ( 0 , out long value ) ;
39+ messageHandle = new IntPtr ( value ) ;
40+
41+ return false ;
42+ }
43+ }
4444 }
4545
4646 public static void SendMessage ( string message )
You can’t perform that action at this time.
0 commit comments