Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions SmartThreadPool/SmartThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ public partial class SmartThreadPool : WorkItemsGroupBase, IDisposable
/// </summary>
private bool _isDisposed;

/// <summary>
/// Indicate whether the SmartThreadPool is idle
/// </summary>
private bool _isIdle;

/// <summary>
/// Holds all the WorkItemsGroup instaces that have at least one
/// work item int the SmartThreadPool
Expand Down Expand Up @@ -338,6 +343,11 @@ public partial class SmartThreadPool : WorkItemsGroupBase, IDisposable
/// </summary>
private event ThreadTerminationHandler _onThreadTermination;

/// <summary>
/// The OnIdle event
/// </summary>
private event WorkItemsGroupIdleHandler _onIdle;

#endregion

#region Per thread properties
Expand Down Expand Up @@ -1589,6 +1599,20 @@ public override int WaitingCallbacks
}
}

public new bool IsIdle
{
get => _isIdle;
protected set
{
// Fire only when we're setting the state to idle and if it wasn't idle already
if (value && !_isIdle)
{
_onIdle?.Invoke(this);
}
_isIdle = value;
}
}

/// <summary>
/// Get an array with all the state objects of the currently running items.
/// The array represents a snap shot and impact performance.
Expand Down Expand Up @@ -1670,21 +1694,11 @@ public override bool WaitForIdle(int millisecondsTimeout)
/// <summary>
/// This event is fired when all work items are completed.
/// (When IsIdle changes to true)
/// This event only work on WorkItemsGroup. On SmartThreadPool
/// it throws the NotImplementedException.
/// </summary>
public override event WorkItemsGroupIdleHandler OnIdle
{
add
{
throw new NotImplementedException("This event is not implemented in the SmartThreadPool class. Please create a WorkItemsGroup in order to use this feature.");
//_onIdle += value;
}
remove
{
throw new NotImplementedException("This event is not implemented in the SmartThreadPool class. Please create a WorkItemsGroup in order to use this feature.");
//_onIdle -= value;
}
add => _onIdle += value;
remove => _onIdle -= value;
}

internal override void PreQueueWorkItem()
Expand Down