Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty CallingAbort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public void ProcessingDone() { _JobDone.Set(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
JobTrigger
should do something along these lines:
job.ProcessingStarted();
... // process job
job.ProcessingDone();
Then something can wait on the job. As mentioned by svick the above code might not scale well if you have many jobs to wait on. Try StackOverflow if you need help solving this specific problem.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public void ProcessingDone() { _JobDone.Set(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
JobTrigger
should do something along these lines:
job.ProcessingStarted();
... // process job
job.ProcessingDone();
Then something can wait on the job. As mentioned by svick the above code might not scale well if you have many jobs to wait on. Try StackOverflow if you need help solving this specific problem.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public void ProcessingDone() { _JobDone.Set(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
JobTrigger
should do something along these lines:
job.ProcessingStarted();
... // process job
job.ProcessingDone();
Then something can wait on the job. As mentioned by svick the above code might not scale well if you have many jobs to wait on. Try StackOverflow if you need help solving this specific problem.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public void ProcessingDone() { _JobDone.Set(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
ProcessingStarted
needs to be called by the JobTrigger
which apparently executesshould do something along these lines:
job.ProcessingStarted();
... // process job
job.ProcessingDone();
Then something can wait on the tasksjob. As mentioned by svick the above code might not scale well if you have many jobs to wait on. Try StackOverflow if you need help solving this specific problem.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
ProcessingStarted
needs to be called by the JobTrigger
which apparently executes the tasks.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public void ProcessingDone() { _JobDone.Set(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
JobTrigger
should do something along these lines:
job.ProcessingStarted();
... // process job
job.ProcessingDone();
Then something can wait on the job. As mentioned by svick the above code might not scale well if you have many jobs to wait on. Try StackOverflow if you need help solving this specific problem.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
ProcessingStarted
needs to be called by the JobTrigger
which apparently executes the tasks.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public async WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
ProcessingStarted
needs to be called by the JobTrigger
which apparently executes the tasks.
Using
Equals(object, null)
to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred overobject == null
.Why is
Parallel
a nullable bool? I can't see any code which relies of the tri-state nature. If you insist on keeping it then a more concise way of checking it for true isif (Parallel == true)
which will only evaluate to true if it is not null and true.Parallel
is not a good name for a boolean flag.RunJobsInParallel
is a bit longer but makes it much more clear what the flag is doing.Calling
Abort()
to terminate a thread is nasty. Use a flag which the main scheduler methods checks at convenient points in order to exit early. UseJoin
with a timeout to wait for the worker thread._jobs
is not thread safe. You iterate over it inReviewJobs
on the worker thread and you have public remove methods which could be called from a different thread to remove jobs from the list. This is waiting for an exception to happen ("collection was modified during enumeration").Actually upon reading your code more carefully:
jobsToExecute
is anIEnumerable
and because it's built by a LINQ statement this means you "only" have a set of nested enumerators which iterate over the original_jobs
collection when you do yourforeach
. This means your code should fail when you call_jobs.Remove()
inside that loop.jobsToExecute
needs to be built withToList()
orToArray()
to create a independent copy.If you want to wait for specific jobs to finish then you can put a
ManualResetEvent
on theJob
class. This should be set by whoever executes the job once it is finished. Expose aWaitAsync()
method on theJob
class to wait on the event. Something along these lines:public class Job { ... private ManualResetEventSlim _JobDone = new ManualResetEventSlim(false); public void ProcessingStarted() { _JobDone.Reset(); } public async Task WaitAsync() { await Task.Run(() => _JobDone.WaitOne()); } }
ProcessingStarted
needs to be called by the JobTrigger
which apparently executes the tasks.