Async await cancelations during Send #983
Unanswered
mwpowellhtx
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was noticing that during a WPF dispatch timer (
Tick
) event, I did anIMessenger.Send<T>
, and during that, myIRecipient<T>.Receive(T)
function wasasync await
. In theory that is an implementation detail, and for reasons, the stuff I was doing, is necessarily alsoasync
so need toawait
. It's not long lived enough to justify a background or worker thread, so messaging makes sense...But what I soon discovered, the operation was encountering a canceled state, probably wrapped by an
AggregateException
as well. My workaround, at the moment, was to factor theasync await
stuff to a different method, and to:Which seems to work, which I think is probably affording a non-canceling token.
First, though, I wondered if others have encountered a similar such behavior, canceled operations during
async await
methods, and identified some plausible workarounds.Second, is it okay from the sender perspective, I think, to send during the
DispatchTimer.Tick
. I have a Semaphore guarding the timer being invoked, because I do not want to pile up overlapping messaging requests, obviously, and it is okay if perhaps we miss one or two during the current response.Ideally, I'd like to kick off something
Task
oriented and have them all be running together, if possible. But for theasync await
cancelation issue.Secondary to all that is, during the
DispatchTimer.Tick
, which was blocking the UI thread. But I think I have that sorted out by virtue ofDispatcherPriority.ApplicationIdle
.But if there are any other or better insights, I am open to considering what those might be.
Beta Was this translation helpful? Give feedback.
All reactions