|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Leaf.Parallel
{
/// <summary>
/// Factory class used to make NTask<T,T>
/// </summary>
public static class NTaskFactory
{
public static NTask<TState, TReturnValue> Build<TState, TReturnValue>(Func<TState, TReturnValue> routine, TState state)
{
return new NTask<TState, TReturnValue>
{
Routine = routine,
State = state
};
}
}
/// <summary>
/// Asynchous Task Information
/// </summary>
/// <typeparam name="TState">state variable type</typeparam>
/// <typeparam name="TReturnValue">return value type</typeparam>
public class NTask<TState, TReturnValue>
{
Func<TState , TReturnValue> routine;
TState state;
NResult<TReturnValue> result;
#region Properties
/// <summary>
/// The routine for the task
/// </summary>
public Func<TState, TReturnValue> Routine
{
get
{
return routine;
}
set
{
routine = value;
}
}
/// <summary>
/// Parameter needed for Routine
/// </summary>
public TState State
{
get
{
return state;
}
set
{
state = value;
}
}
/// <summary>
/// Return value holder
/// </summary>
public NResult<TReturnValue> Result
{
get
{
return result;
}
internal set
{
result = value;
}
}
#endregion
public void Run()
{
result = NParallel.Execute(state, routine);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Leaf is a software developer based in ShangHai China.
My major programming languages are C#/C++.
I am very interested in distributed system design and rich client development.
Current I am working on
NParallel.