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()
173
173
void SetTimeout ( IAsyncResult asyncResult )
174
174
{
175
175
if ( Timeout != 0 )
176
- ThreadPool . RegisterWaitForSingleObject (
176
+ _timeoutState . Handle = ThreadPool . RegisterWaitForSingleObject (
177
177
asyncResult . AsyncWaitHandle ,
178
178
TimeoutCallback , _timeoutState , Timeout , true
179
179
) ;
180
180
181
181
static void TimeoutCallback ( object state , bool timedOut )
182
182
{
183
- if ( ! timedOut )
184
- return ;
185
-
186
183
if ( ! ( state is TimeOutState tos ) )
187
184
return ;
188
185
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
+ }
190
199
191
200
tos . Request ? . Abort ( ) ;
192
201
}
@@ -286,6 +295,8 @@ class TimeOutState
286
295
public bool TimedOut { get ; set ; }
287
296
288
297
public HttpWebRequest ? Request { get ; set ; }
298
+
299
+ public RegisteredWaitHandle ? Handle { get ; set ; }
289
300
}
290
301
}
291
302
}
You can’t perform that action at this time.
0 commit comments