سلام بر تمامی برنامه نویسان عزیز 😉 در این مطلب آموزش ResetAbort() برای Thread در #C را آماده کردم. امیدوارم که این کد برای شما مفید باشد.
کد ResetAbort() برای Thread در #C :
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 + " starting.");
for(int i = 1; i <= 100; i++) {
try {
Console.Write(i + " ");
Thread.Sleep(50);
} catch(ThreadAbortException exc) {
if((int)exc.ExceptionState == 0) {
Console.WriteLine("Abort Cancelled! Code is " + exc.ExceptionState);
Thread.ResetAbort();
} else
Console.WriteLine("Thread aborting, code is " + exc.ExceptionState);
}
}
Console.WriteLine(thrd.Name + " exiting normally.");
}
}
class MainClass {
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 + " starting.");
for(int i = 1; i <= 100; i++) {
try {
Console.Write(i + " ");
Thread.Sleep(50);
} catch(ThreadAbortException exc) {
if((int)exc.ExceptionState == 0) {
Console.WriteLine("Abort Cancelled! Code is " + exc.ExceptionState);
Thread.ResetAbort();
} else
Console.WriteLine("Thread aborting, code is " + exc.ExceptionState);
}
}
Console.WriteLine(thrd.Name + " exiting normally.");
}
}
class MainClass {