.
.
Abort () , . , , .
Abort ()
Abort (), :
public void Abort(object statelnfo)
statelnfo , , . ExceptionState ThreadAbortException. . Abort ().
// Abort (object statelnfo).
Using System;
Using System.Threading;
class MyThread {
Public Thread Thrd;
public MyThread(string name) {
Thrd = new Thread(this.Run);
Thrd.Name = name;
Thrd.Start();
}
// , void Run() { try {
Console.WriteLine(Thrd.Name + " .");
for (int i = 1; i <= 1000; i++) {
Console.Write(i + " "); if((i%10)==0) {
Console.WriteLine();
Thread.Sleep(250);
}
}
Console.WriteLine(Thrd.Name + " .");
} catch(ThreadAbortException exc) {
Console.WriteLine(" , " + exc.ExceptionState);
>
)
}
class UseAltAbort { static void Main() {
MyThread mtl = new MyThread(" ");
Thread.Sleep(1000); // Console.WriteLine(" ."); mtl.Thrd.Abort(100);
Console.WriteLine(" .");
}
}
.
.
, 100 .
, 100 Abort () . ExceptionState ThreadAbortException, .
Abort ()
. ThreadAbortException, ResetAbort (). , . ResetAbort().
Public static void ResetAbort()
ResetAbort () , .
ResetAbort().
|
|
// ResetAbort().
Using System;
Using System.Threading;
class MyThread {
Public Thread Thrd;
public MyThread(string name) {
Thrd = new Thread(this.Run);
Thrd.Name = name;
Thrd.Start();
}
// , void Run() {
Console.WriteLine(Thrd.Name + "..");
try {
Console.Write(i + " "); if((i %10)==0) {
Console.WriteLine ();
Thread.Sleep (250);
}
} catch(ThreadAbortException exc) { if((int)exc.ExceptionState ==0) {
Console.WriteLine(" ! " +
" " + exc.ExceptionState);
Thread.ResetAbort();
}
Else
Console.WriteLine(" , " + exc.ExceptionState);
' }
}
Console.WriteLine(Thrd.Name + " .");
}
}
class ResetAbort { static void Main() {
MyThread mtl = new MyThread(" ");
Thread.Sleep(1000); //
Console.WriteLine(" ."); mtl.Thrd.Abort(0); //
Thread.Sleep(1000); //
Console.WriteLine(" ."); i
mtl.Thrd.Abort(100); //
mtl.Thrd.Join(); //
Console.WriteLine(" .");
}
}