Handle server.SendAsync() errors
Closed this issue · 2 comments
willem-syt commented
Hi,
First of all thank you for this great package.
I am using it to send json data to client apps, so I started from the example code in Server.cs:
bool success = _Server.SendAsync(guid, data).Result;
if (!success) Console.WriteLine("Failed");
However I found that in case of (connection/network) errors, this could block the code, so I changed that to use await:
bool success = await _Server.SendAsync(guid, data);
if (!success) Console.WriteLine("Failed");
That resolved the blocking, but I still found that in case of (connection/network) errors the server seemed to retry sending the data (and give a long log of 'disposed' errors).
Is there something I can do about that (maybe with the Cancelation token argument)?
Thanks, Willem
(Note: the code above is simplified)
willem-syt commented
Added
using (var tokesSource = new CancellationTokenSource(150))
{
bool result = await _Server.SendAsync(guid, data, tokesSource.Token);
This reduced the amount of errors.
jchristn commented
Hi @willem-syt I'm so sorry I'm just now seeing this, I'm glad you found a way around it.