##// END OF EJS Templates
minor fixes and improvements of AsyncQueue, additional tests
minor fixes and improvements of AsyncQueue, additional tests

File last commit:

r76:c761fc982e1d v2
r122:0c8685c8b56b v2
Show More
TaskController.cs
136 lines | 3.5 KiB | text/x-csharp | CSharpLexer
cin
inital progress handling
r7 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Implab
{
/// <summary>
/// This class allows to interact with asyncronuos task.
/// </summary>
/// <remarks>
/// Members of this object are thread safe.
/// </remarks>
cin
refactoring
r25 public class TaskController: IProgressNotifier, ITaskController
cin
inital progress handling
r7 {
cin
implemeted new cancellable promises concept
r10 readonly object m_lock;
cin
inital progress handling
r7 string m_message;
float m_current;
float m_max;
cin
refactoring, added WorkerPool
r12 bool m_cancelled;
cin
refactoring
r25 public event EventHandler Cancelled;
cin
inital progress handling
r7 public event EventHandler<ValueEventArgs<string>> MessageUpdated;
public event EventHandler<ValueEventArgs<float>> ProgressUpdated;
public event EventHandler<ProgressInitEventArgs> ProgressInit;
public TaskController()
{
m_lock = new Object();
}
public string Message
{
get
{
lock (m_lock)
return m_message;
}
set
{
lock (m_lock)
{
m_message = value;
OnMessageUpdated();
}
}
}
public float CurrentProgress
{
get
{
lock (m_lock)
return m_current;
}
set
{
lock (m_lock)
{
var prev = m_current;
m_current = value;
if (m_current >= m_max)
m_current = m_max;
if (m_current != prev)
OnProgressUpdated();
}
}
}
public void InitProgress(float current, float max, string message)
{
if (max < 0)
throw new ArgumentOutOfRangeException("max");
if (current < 0 || current > max)
throw new ArgumentOutOfRangeException("current");
lock(m_lock) {
m_current = current;
m_max = max;
m_message = message;
OnProgressInit();
}
}
cin
refactoring
r25 public bool IsCancelled {
cin
refactoring, added WorkerPool
r12 get {
lock (m_lock)
return m_cancelled;
}
}
cin
Refactoring of the IPromise<T> interface...
r76 public void Cancel() {
cin
refactoring, added WorkerPool
r12 lock (m_lock) {
cin
Refactoring of the IPromise<T> interface...
r76 if (!m_cancelled)
cin
refactoring, added WorkerPool
r12 m_cancelled = true;
}
}
cin
refactoring
r25 protected virtual void OnCancelled() {
var temp = Cancelled;
if (temp != null) {
temp(this,new EventArgs());
}
}
cin
inital progress handling
r7 protected virtual void OnMessageUpdated()
{
var temp = MessageUpdated;
if (temp != null)
{
temp(this, new ValueEventArgs<string>(m_message));
}
}
protected virtual void OnProgressUpdated()
{
var temp = ProgressUpdated;
if (temp != null)
{
temp(this,new ValueEventArgs<float>(m_current));
}
}
protected virtual void OnProgressInit()
{
var temp = ProgressInit;
if (temp != null)
{
temp(this, new ProgressInitEventArgs(m_current,m_max, m_message));
}
}
}
}