File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -173,20 +173,29 @@ long CalculateContentLength()
173173 void SetTimeout ( IAsyncResult asyncResult )
174174 {
175175 if ( Timeout != 0 )
176- ThreadPool . RegisterWaitForSingleObject (
176+ _timeoutState . Handle = ThreadPool . RegisterWaitForSingleObject (
177177 asyncResult . AsyncWaitHandle ,
178178 TimeoutCallback , _timeoutState , Timeout , true
179179 ) ;
180180
181181 static void TimeoutCallback ( object state , bool timedOut )
182182 {
183- if ( ! timedOut )
184- return ;
185-
186183 if ( ! ( state is TimeOutState tos ) )
187184 return ;
188185
189- lock ( tos ) tos . TimedOut = true ;
186+ lock ( tos )
187+ {
188+ if ( ! timedOut )
189+ {
190+ if ( tos . Handle != null )
191+ {
192+ tos . Handle . Unregister ( null ) ;
193+ }
194+ return ;
195+ }
196+
197+ tos . TimedOut = true ;
198+ }
190199
191200 tos . Request ? . Abort ( ) ;
192201 }
@@ -286,6 +295,8 @@ class TimeOutState
286295 public bool TimedOut { get ; set ; }
287296
288297 public HttpWebRequest ? Request { get ; set ; }
298+
299+ public RegisteredWaitHandle ? Handle { get ; set ; }
289300 }
290301 }
291302}
You can’t perform that action at this time.
0 commit comments