@@ -40,7 +40,18 @@ static NWPathMonitor SharedMonitor
4040
4141 static NWPath GetCurrentPath ( )
4242 {
43- return SharedMonitor ? . CurrentPath ;
43+ var monitor = SharedMonitor ;
44+ var path = monitor ? . CurrentPath ;
45+
46+ // If path is null, the monitor might not have received its first update yet
47+ // Force initialization by accessing the monitor
48+ if ( path == null && monitor != null )
49+ {
50+ // Monitor is started but path not yet available - this is expected on first call
51+ // The monitor will update CurrentPath asynchronously
52+ }
53+
54+ return path ;
4455 }
4556
4657 internal static NetworkStatus RemoteHostStatus ( )
@@ -120,7 +131,7 @@ internal ReachabilityListener()
120131 ReachabilityChanged ? . Invoke ( ) ;
121132 } ;
122133
123- pathMonitor . SnapshotHandler + = pathUpdateHandler ;
134+ pathMonitor . SnapshotHandler = pathUpdateHandler ;
124135 pathMonitor . SetQueue ( DispatchQueue . DefaultGlobalQueue ) ;
125136 pathMonitor . Start ( ) ;
126137
@@ -139,11 +150,8 @@ internal void Dispose()
139150 {
140151 if ( pathMonitor != null )
141152 {
142- if ( pathUpdateHandler != null )
143- {
144- pathMonitor . SnapshotHandler -= pathUpdateHandler ;
145- pathUpdateHandler = null ;
146- }
153+ pathMonitor . SnapshotHandler = null ;
154+ pathUpdateHandler = null ;
147155 pathMonitor . Cancel ( ) ;
148156 pathMonitor . Dispose ( ) ;
149157 pathMonitor = null ;
0 commit comments