@@ -76,9 +76,12 @@ public OperationResult<TValue> Invoke<TValue> (AsyncOperationBase<TValue> mc, in
76
76
return task . Result ;
77
77
}
78
78
DebuggerLoggingService . LogMessage ( string . Format ( "Invoke {0} timed out after {1} ms. Cancelling." , description , timeout ) ) ;
79
- mc . Abort ( ) ;
79
+ var abortCalled = mc . AbortCalled ;
80
+ // if abort was already called (in AbortAll/Dispose) don't call it again, just wait
81
+ if ( ! abortCalled )
82
+ mc . Abort ( ) ;
80
83
try {
81
- WaitAfterCancel ( mc ) ;
84
+ WaitAfterCancel ( mc , abortCalled ) ;
82
85
}
83
86
catch ( Exception e ) {
84
87
if ( IsOperationCancelledException ( e ) ) {
@@ -119,7 +122,7 @@ void ChangeBusyState (bool busy, string description)
119
122
}
120
123
}
121
124
122
- void WaitAfterCancel ( IAsyncOperationBase op )
125
+ void WaitAfterCancel ( IAsyncOperationBase op , bool onlyWait )
123
126
{
124
127
var desc = op . Description ;
125
128
DebuggerLoggingService . LogMessage ( string . Format ( "Waiting for cancel of invoke {0}" , desc ) ) ;
@@ -131,7 +134,9 @@ void WaitAfterCancel (IAsyncOperationBase op)
131
134
if ( disposed )
132
135
break ;
133
136
}
134
- op . Abort ( ) ;
137
+ if ( ! onlyWait ) {
138
+ op . Abort ( ) ;
139
+ }
135
140
if ( op . RawTask . Wait ( ShortCancelTimeout ) )
136
141
break ;
137
142
}
@@ -160,9 +165,13 @@ void CancelOperations (List<IAsyncOperationBase> operations, bool wait)
160
165
foreach ( var operation in operations ) {
161
166
var taskDescription = operation . Description ;
162
167
try {
163
- operation . Abort ( ) ;
168
+ var abortCalled = operation . AbortCalled ;
169
+ // if abort was already called (in AbortAll/Dispose) don't call it again, just wait
170
+ if ( ! abortCalled ) {
171
+ operation . Abort ( ) ;
172
+ }
164
173
if ( wait ) {
165
- WaitAfterCancel ( operation ) ;
174
+ WaitAfterCancel ( operation , abortCalled ) ;
166
175
}
167
176
}
168
177
catch ( Exception e ) {
0 commit comments