Home Timeout in Async Method
Reply: 0

Timeout in Async Method

user1442 Published in March 23, 2018, 9:01 am

I have an async Method named "RequestMessage()". Within this method, I'm going to send a message to a message broker. Since I don't know when to expect the result, I'm using "TaskCompletionSource". I want the async method to terminate, when the reply message arrived (I'll receive an event from the broker).

This works fine so far. Now, my issue is that this message could never be answered, or at least way to late.

I'm looking for a change to implement my own timeout. To do so, I tried a Timer, as well as the Observer of Reactive Extensions. Th issue is always the same - I can't get my main thread and the timer thread syncronized, as I'm using .NET Core 2 and there is no SynchronizationContext.

So, in my code there is an observer ..

            x =>

If time expires a callback should be called. In my caller method, I handle the callback this way:

    TimeoutDelegate timeoutHandler = () => throw new WorkcenterRepositoryCommunicationException("Broker communication timed out.", null);

As you realized already, this Exception will never be catched, as it is not thrown to the main thread.

How can I sync threads here?

Thanks in advance!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.49917 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO