Make it stop
@@ -35,8 +35,6 @@ namespace Miningcore.Mining
this.clock = clock;
this.messageBus = messageBus;
-
- disposables.Add(cts);
}
private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
@@ -72,6 +70,7 @@ namespace Miningcore.Mining
Task.Run(() =>
{
Thread.CurrentThread.Name = "ShareReceiver Socket Poller";
+ var timeout = TimeSpan.FromMilliseconds(1000);
while (!cts.IsCancellationRequested)
{
@@ -94,15 +93,14 @@ namespace Miningcore.Mining
return subSocket;
}).ToArray();
- // disposing the sockets in the Stop() method will cause polling to abort, terminating this thread
- disposables.Add(new CompositeDisposable(sockets));
-
+ using (new CompositeDisposable(sockets))
+ {
// setup poll-items
var pollItems = sockets.Select(_ => ZPollItem.CreateReceiver()).ToArray();
while (!cts.IsCancellationRequested)
{
- if (sockets.PollIn(pollItems, out var messages, out var error))
+ if (sockets.PollIn(pollItems, out var messages, out var error, timeout))
{
// emit received messages
for (var i = 0; i < messages.Length; i++)
@@ -123,10 +121,6 @@ namespace Miningcore.Mining
}
}
}
-
- catch (ObjectDisposedException)
- {
- break;
}
catch (Exception ex)
