I have written a C# program to call a function through backgndWorkerEnroll_DoWork
which in turn calls another function through a thread. After I start the thread the first time, the function works properly. I then abort the thread using the thread.Abort()
method and call thread.Start()
method again. The previous function call still works, it doesn't abort. How can I force shutdown the thread?
public int capture()
{
System.Threading.Thread thEnroll = new System.Threading.Thread(delegate()
{
// winbio.OpenSession1();
refresult1 = winbio.Enroll1(finger, false, refresult);
//winbio.Enroll1(finger, false, refresult, out refresult1);
});
thEnroll.Name = "thEnroll";
thEnroll.Start();
while (true)
{
if (!thEnroll.IsAlive)
break;
}
thEnroll.Abort();
return result;
}
private void backgndWorkerEnroll_DoWork(object sender, DoWorkEventArgs e)
{
capture();
}
and also one more query.how to force close the backgroundDo_Work through button click event.