Skip to content

Commit 712af40

Browse files
committed
RELEASE v2.3.1 - comments and readme.md
1 parent b13462d commit 712af40

7 files changed

Lines changed: 34 additions & 31 deletions

File tree

Base.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,20 @@ protected virtual void executeTask (Task task) {
209209
object taskResult = null;
210210
object taskJob = task.Job;
211211
try {
212-
if (taskJob is TaskDelegate) {
213-
(taskJob as TaskDelegate).Invoke(this);
214-
} else if (taskJob is Func<Base, object>) {
215-
taskResult = (taskJob as Func<Base, object>).Invoke(this);
216-
} else {
217-
throw new Exception("Pooler task has to be type 'delegate', 'Pooler.TaskDelegate' (void accepting first param to be 'Pooler.Base') or 'Func<Pooler.Base, object>'.");
212+
if (taskJob is ParallelTaskDelegate) {
213+
(taskJob as ParallelTaskDelegate).Invoke(this as Parallel);
214+
} else if (taskJob is RepeaterTaskDelegate) {
215+
(taskJob as RepeaterTaskDelegate).Invoke(this as Repeater);
216+
} else if (taskJob is Func<Parallel, object>) {
217+
taskResult = (taskJob as Func<Parallel, object>).Invoke(this as Parallel);
218+
} else if (taskJob is Func<Repeater, object>) {
219+
taskResult = (taskJob as Func<Repeater, object>).Invoke(this as Repeater);
220+
} else {
221+
throw new Exception(
222+
"Pooler task has to be type: "
223+
+ "Pooler.ParallelTaskDelegate | Pooler.RepeaterTaskDelegate | "
224+
+ "Func<Pooler.Parallel, object> | Func<Pooler.Repeater, object>."
225+
);
218226
}
219227
} catch (Exception e) {
220228
lock (this.exceptionsLock) {

Delegates.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@
2121
/// Any delegate added internaly into tasks store in Add() method with no params section or with single param accepting Pooler.Base type.
2222
/// </summary>
2323
/// <param name="pool">threads instance pool instance.</param>
24-
public delegate void TaskDelegate (Base pool);
24+
public delegate void ParallelTaskDelegate (Parallel pool);
2525
/// <summary>
2626
/// Any delegate added internaly into tasks store in Add() method with no params section or with single param accepting Pooler.Base type.
2727
/// </summary>
2828
/// <param name="pool">threads instance pool instance.</param>
29-
public delegate void TaskDelegateParallel (Parallel pool);
30-
/// <summary>
31-
/// Any delegate added internaly into tasks store in Add() method with no params section or with single param accepting Pooler.Base type.
32-
/// </summary>
33-
/// <param name="pool">threads instance pool instance.</param>
34-
public delegate void TaskDelegateRepeater (Repeater pool);
29+
public delegate void RepeaterTaskDelegate (Repeater pool);
3530
}

Parallel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Parallel Add (Func<Parallel, object> task, bool runInstantly = true, Thre
9393
/// <param name="priority">Background thread priority for task executing.</param>
9494
/// <param name="async">If task is using any other threads to work or async code, set this to true and call pool.AsyncTaskDone() call after your task is done manualy.</param>
9595
/// <returns>Current threads pool instance.</returns>
96-
public Parallel Add (TaskDelegateParallel task, bool runInstantly = true, ThreadPriority priority = ThreadPriority.Normal, bool async = false) {
96+
public Parallel Add (ParallelTaskDelegate task, bool runInstantly = true, ThreadPriority priority = ThreadPriority.Normal, bool async = false) {
9797
lock (this.runningTasksLock) {
9898
this._store.Add(new Task {
9999
Job = task,

Pooler.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>Pooler</id>
5-
<version>2.3.0.0</version>
5+
<version>2.3.1.0</version>
66
<title>Pooler</title>
77
<authors>Tom Flidr</authors>
88
<owners>Tom Flidr</owners>

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
// You can specify all the values or you can default the Build and Revision Numbers
3737
// by using the '*' as shown below:
3838
// [assembly: AssemblyVersion("1.0.*")]
39-
[assembly: AssemblyVersion("2.3.0.0")]
40-
[assembly: AssemblyFileVersion("2.3.0.0")]
39+
[assembly: AssemblyVersion("2.3.1.0")]
40+
[assembly: AssemblyFileVersion("2.3.1.0")]

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Pooler.Parallel pool = Pooler.Parallel.CreateNew(10);
3333
for (int i = 0; i < 500; i++) {
3434
pool.Add(
3535
// any delegate or void to process
36-
(Pooler.Base pool) => {
36+
(Pooler.Parallel pool) => {
3737
double dummyResult = Math.Pow(Math.PI, Math.PI);
3838
},
3939
// optional - do not run task instantly after adding, run them a few lines later together
@@ -55,13 +55,13 @@ pool.Add(delegate {
5555
double dummyResult = Math.Pow(Math.PI, Math.PI);
5656
});
5757
// ... or to add task as any void function accepting first param as Pooler type:
58-
pool.Add((Pooler.Base p) => {
58+
pool.Add((Pooler.Parallel p) => {
5959
double dummyResult = Math.Pow(Math.PI, Math.PI);
6060
});
6161

62-
// ... or to add task as Func<Pooler.Base, object> function:
62+
// ... or to add task as Func<Pooler.Parallel, object> function:
6363
// accepting first param as Pooler type and returning any result:
64-
pool.Add((Pooler.Base p) => {
64+
pool.Add((Pooler.Parallel p) => {
6565
return Math.Pow(Math.PI, Math.PI);
6666
});
6767
// ... then you can pick up returned result in pool.TaskDone event:
@@ -141,7 +141,7 @@ int pausemiliseconds = pool.GetPauseMiliseconds();
141141

142142
2. Use `pool.Pause();` method sometimes in your hard task:
143143
```cs
144-
pool.Add((Pooler.Base p) => {
144+
pool.Add((Pooler.Parallel p) => {
145145
double someHardCode1 = Math.Pow(Math.PI, Math.PI);
146146
p.Pause();
147147
double someHardCode2 = Math.Pow(Math.PI, Math.PI);
@@ -169,7 +169,7 @@ pool = Pooler.Repeater.CreateNew(10, 500, 100);
169169
pool = new Pooler.Repeater(10, 500, 100);
170170
```
171171
- First (optional) param is max. threads in background to executing one specific task. 10 by default.
172-
- Second (optional) param is how many times will be specific task executed. Null means infinite, then you need to use pool.StopAll(); somewhere in the future manualy.
172+
- Second (optional) param is how many times will be specific task executed. Null means infinite (zero - 0 - doesn't means infinite), then you need to use pool.StopAll(); or pool.StopCurrent(); somewhere in the task body in the future future manualy.
173173
- Third (optional) param is pause miliseconds to slow down CPU load or other resources by `pool.Pause();` calls inside your task, 0 by default.
174174

175175
#### Repeater instance and single specific task setup:
@@ -180,13 +180,13 @@ pool.Set(delegate {
180180
double dummyResult = Math.Pow(Math.PI, Math.PI);
181181
});
182182
// ... or set task as any void function accepting first param as Pooler type:
183-
pool.Set((Pooler.Base p) => {
183+
pool.Set((Pooler.Repeater p) => {
184184
double dummyResult = Math.Pow(Math.PI, Math.PI);
185185
});
186186

187-
// ... or set task as Func<Pooler.Base, object> function:
187+
// ... or set task as Func<Pooler.Repeater, object> function:
188188
// accepting first param as Pooler type and returning any result:
189-
pool.Set((Pooler.Base p) => {
189+
pool.Set((Pooler.Repeater p) => {
190190
return Math.Pow(Math.PI, Math.PI);
191191
});
192192
// ... then you can pick up returned result as before in pool.TaskDone event:
@@ -223,7 +223,7 @@ To use any other threads or async code in your pool tasks, you need to tell pool
223223
```cs
224224
pool.Add(
225225
// any delegate or void to process
226-
(Pooler.Base pool) => {
226+
(Pooler.Parallel pool) => {
227227
// some async code start here:
228228
CustomDownloader client = new CustomDownloader(
229229
"http://example.com/something/what/takes/some/time/to/load"

Repeater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Repeater: Base {
3838
/// Create and return new threads pool instance, nowhere regstered, just created.
3939
/// </summary>
4040
/// <param name="maxRunningTasks">Max threads running in parallel to execute given tasks.</param>
41-
/// <param name="tasksCount">Tasks count to process repeatedly, zero means infinite.</param>
41+
/// <param name="tasksCount">Tasks count to process repeatedly, null means infinite.</param>
4242
/// <param name="pauseMiliseconds">Miliseconds for pooler.Pause(); call inside any task to slow down CPU or any other computer resources for each running thread in threads pool.</param>
4343
public Repeater (int maxRunningTasks = 10, int? tasksCount = null, int pauseMiliseconds = 0) : base(maxRunningTasks, pauseMiliseconds) {
4444
this._tasksCount = tasksCount;
@@ -47,7 +47,7 @@ public Repeater (int maxRunningTasks = 10, int? tasksCount = null, int pauseMili
4747
/// Get single instance from Parallel.instance place created only once.
4848
/// </summary>
4949
/// <param name="maxRunningTasks">Max threads running in parallel to execute given tasks.</param>
50-
/// <param name="tasksCount">Tasks count to process repeatedly, zero means infinite.</param>
50+
/// <param name="tasksCount">Tasks count to process repeatedly, null means infinite.</param>
5151
/// <param name="pauseMiliseconds">Miliseconds for pooler.Pause(); call inside any task to slow down CPU or any other computer resources for each running thread in threads pool.</param>
5252
/// <returns>static instance created only once.</returns>
5353
public static Repeater GetStaticInstance (int maxRunningTasks = Base.RUNNING_TASKS_MAX_DEFAULT, int? tasksCount = null, int pauseMiliseconds = Base.PAUSE_MILESECONDS_DEFAULT) {
@@ -60,7 +60,7 @@ public static Repeater GetStaticInstance (int maxRunningTasks = Base.RUNNING_TAS
6060
/// Create and return new threads pool instance, nowhere regstered, just created.
6161
/// </summary>
6262
/// <param name="maxRunningTasks">Max threads running in parallel to execute given tasks.</param>
63-
/// <param name="tasksCount">Tasks count to process repeatedly, zero means infinite.</param>
63+
/// <param name="tasksCount">Tasks count to process repeatedly, null means infinite.</param>
6464
/// <param name="pauseMiliseconds">Miliseconds for pooler.Pause(); call inside any task to slow down CPU or any other computer resources for each running thread in threads pool.</param>
6565
/// <returns>New threads pool instance to use.</returns>
6666
public static Repeater CreateNew (int maxRunningTasks = Base.RUNNING_TASKS_MAX_DEFAULT, int? tasksCount = null, int pauseMiliseconds = Base.PAUSE_MILESECONDS_DEFAULT) {
@@ -124,7 +124,7 @@ public Repeater Set (Func<Repeater, object> task, bool runInstantly = true, Thre
124124
/// <param name="priority">Background thread priority for task executing.</param>
125125
/// <param name="async">If task is using any other threads to work or async code, set this to true and call pool.AsyncTaskDone() call after your task is done manualy.</param>
126126
/// <returns>Current threads pool instance.</returns>
127-
public Repeater Set (TaskDelegateRepeater task, bool runInstantly = true, ThreadPriority priority = ThreadPriority.Normal, bool async = false) {
127+
public Repeater Set (RepeaterTaskDelegate task, bool runInstantly = true, ThreadPriority priority = ThreadPriority.Normal, bool async = false) {
128128
lock (this.runningTasksLock) {
129129
this._task = new Task {
130130
Job = task,

0 commit comments

Comments
 (0)