public async ValueTask <Ice.OutputStream> DispatchAsync(Ice.InputStream istr, Current current) { if (current.Context.TryGetValue("raiseBeforeDispatch", out var context)) { if (context.Equals("invalidInput")) { throw new Test.InvalidInputException(); } else if (context.Equals("notExist")) { throw new Ice.ObjectNotExistException(); } } _lastOperation = current.Operation; if (_lastOperation.Equals("addWithRetry") || _lastOperation.Equals("amdAddWithRetry")) { for (int i = 0; i < 10; ++i) { try { var ostr = await _servant.DispatchAsync(istr, current).ConfigureAwait(false); test(false); } catch (RetryException) { istr.RestartEncapsulation(); // Expected, retry } } current.Context["retry"] = "no"; } else if (current.Context.TryGetValue("retry", out context) && context.Equals("yes")) { // Retry the dispatch to ensure that abandoning the result of the dispatch // works fine and is thread-safe var vt1 = _servant.DispatchAsync(istr, current); istr.RestartEncapsulation(); var vt2 = _servant.DispatchAsync(istr, current); await vt1.ConfigureAwait(false); await vt2.ConfigureAwait(false); } istr.RestartEncapsulation(); var vt = _servant.DispatchAsync(istr, current); AsyncCompletion = !vt.IsCompleted; if (current.Context.TryGetValue("raiseAfterDispatch", out context)) { if (context.Equals("invalidInput")) { throw new Test.InvalidInputException(); } else if (context.Equals("notExist")) { throw new Ice.ObjectNotExistException(); } } return(await vt.ConfigureAwait(false)); }