110,533
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 飞鸽发送开始
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
private bool SendStr(string s,CancellationToken token)
{
lock (TheradLock)
{
bool re = false;
try
{
token.ThrowIfCancellationRequested();
re = InitSendStr(3);
if (re)
{
token.ThrowIfCancellationRequested();
if (magWindow.SetFgText(s))
{
token.ThrowIfCancellationRequested();
re = magWindow.Submit();
if (re)
{ DisplayOperation(new Operation("【成功】发送飞鸽:【"+s+"】",1)); }
else
{ DisplayOperation(new Operation("【失败】发送飞鸽:【" + s + "】", 1)); }
}
this.IsSendStr = re;
}
}
catch (OperationCanceledException ex)
{
DisplayOperation(new Operation("【成功】取消本次飞鸽操作……", 1));
}
return re;
}
}
/// <summary>
/// 开始 异步 发送飞鸽
/// </summary>
/// <param name="ss"> 飞鸽内容 </param>
public void StartSendStr(string[] ss)
{
this.taskList.Clear();
this.feiGeList.Clear();
this.cancelToken = new CancellationTokenSource();
this.feiGeList.AddRange(ss);
foreach (string s in this.feiGeList)
{
Task task = Task.Factory.StartNew(() =>//任务
{ SendStr(s,this.cancelToken.Token); }
,this.cancelToken.Token);
task.ContinueWith((t) =>//任务完成回调
{
if (t.IsCanceled)
{ DisplayOperation(new Operation(s + " 取消成功……", 1)); }
if (t.IsCompleted)
{ DisplayOperation(new Operation(s + " 正常成功……", 1)); }
}
);
this.taskList.Add(task);
}
this.cancelToken.Token.Register(() =>//任务取消回调
{
DisplayOperation(new Operation("以提交取消操作……", 1));
}
);
}
/// <summary>
/// 终止 异步 发送飞鸽
/// </summary>
public void StopSendStr()
{
try
{
this.cancelToken.Cancel();
}
catch (OperationCanceledException ex)
{
//DisplayOperation(new Operation("终止发送飞鸽……", 1));
}
catch (AggregateException e)
{
//foreach (var v in e.InnerExceptions)
// DisplayOperation(new Operation(e.Message + " " + v.Message + "终止发送飞鸽……", 1));
}
catch (ThreadAbortException ex)
{
}
}