Skip to content

Commit 45365a6

Browse files
authored
Merge pull request #917 from AnandKR84/patch-2
Provision to have override long running poller
2 parents 8c46a3d + a7c409d commit 45365a6

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/NetMQ/NetMQPoller.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -39,9 +39,9 @@ public sealed class NetMQPoller :
3939
private readonly StopSignaler m_stopSignaler = new StopSignaler();
4040

4141
private NetMQSelector.Item[]? m_pollSet;
42-
private NetMQSocket[]? m_pollact;
42+
private NetMQSocket[]? m_pollact;
4343

44-
private volatile bool m_isPollSetDirty = true;
44+
private volatile bool m_isPollSetDirty = true;
4545
private int m_disposeState = (int)DisposeState.Undisposed;
4646

4747
#if NET35
@@ -354,7 +354,7 @@ public void Remove(Socket socket)
354354

355355
#region Contains
356356
#if !NET35
357-
357+
358358
/// <summary>
359359
/// Check if poller contains the socket asynchronously.
360360
/// </summary>
@@ -425,12 +425,27 @@ public void RunAsync()
425425
/// </summary>
426426
/// <param name="threadName">The thread name to use.</param>
427427
public void RunAsync(string threadName)
428+
{
429+
RunAsync(threadName, false);
430+
}
431+
432+
/// <summary>
433+
/// Runs the poller in a specified thread - background/foreground, returning once the poller has started.
434+
/// </summary>
435+
/// <param name="threadName">The thread name to use.</param>
436+
/// <param name="isBackgroundThread">Allow the poller thread to be a long running
437+
/// poller (either foreground thread/background)</param>
438+
public void RunAsync(string threadName, bool isBackgroundThread)
428439
{
429440
CheckDisposed();
430441
if (IsRunning)
431442
throw new InvalidOperationException("NetMQPoller is already running");
432443

433-
var thread = new Thread(Run) { Name = threadName };
444+
var thread = new Thread(Run)
445+
{
446+
Name = threadName,
447+
IsBackground = isBackgroundThread
448+
};
434449
thread.Start();
435450

436451
m_switch.WaitForOn();
@@ -473,8 +488,8 @@ public void Run()
473488
/// Runs the poller on the caller's thread. Only returns when <see cref="Stop" /> or <see cref="StopAsync" /> are called from another thread.
474489
/// </summary>
475490
/// <param name="syncContext">The synchronization context that will be used.</param>
476-
public void Run(SynchronizationContext syncContext)
477-
{
491+
public void Run(SynchronizationContext syncContext)
492+
{
478493
if (syncContext == null)
479494
throw new ArgumentNullException("Must supply a Synchronization Context");
480495

0 commit comments

Comments
 (0)