-1
は、私は、次のコードを持っている:C#でアクションを停止するか、スレッドに変更しますか?
void ThreadMethod()
{
Console.WriteLine("Thread..");
}
IAsyncResult actionResult;
Action a = new Action();
Thread t = new Thread(new ThreadStart(ThreadMethod));
actionResult = a.BeginInvoke(ActionCompleted, null);
t.Start();
void ActionCompleted(IAsyncResult ar)
{
if (ar.IsCompleted)
{
Console.WriteLine("Action finished");
t.Abort();
}
}
は私が手動でアクションをどのように停止することができますか? は例
if (actionShouldBeStopped)
{
action.Stop(); // and ActionComplete should be run.
}
のために別のオプションは、スレッドへのアクションを変更することですが、その後どのようにそれは次のようになりますか?スレッドのActionCompletedのようなものを実装するにはどうすればよいですか?
おかげで、 マエストロ
[このSOスレッド:CancellationTokenをロックして聞く](http://stackoverflow.com/q/7416786/485076) – sll