日期:2014-05-20 浏览次数:20740 次
public abstract class HandlersBase
{
protected bool isBusy = false;
protected bool isFinished = true;
protected Task task;
public HandlersBase(string showStr,CancellationToken token)
{
task = Task.Factory.StartNew(Handler,token,token,TaskCreationOptions.LongRunning,TaskScheduler.Default);
MessageModel.Message(string.Format("{0} 启动完成!", showStr));
}
public bool IsHandlersBusy()
{
return isBusy;
}
public abstract bool IsHandlersFinished();
public abstract void Handler(object token);
}
public class TranslatorHandler : HandlersBase
{
public TranslatorHandler(int i,CancellationToken token)
: base("翻译线程" + i.ToString(),token)
{ }
public override void Handler(object token)
{
while (!((CancellationToken)token).IsCancellationRequested)