In my WPF application, I have a long running process which converts files to PDFs using BlueBeam Q Server. When the process takes place, it should not freeze, so the below code has written to take care of that:
private void btn_convert_Click(object sender, RoutedEventArgs e)
{
thread = new Thread(new ThreadStart(WorkerMethod));
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Name = "PDF";
thread.Start();
}
WorkerMethod()
{
//code to connect to Q server and conversion goes here
}
Now, when the process starts, a cancel button will be visible to the user. When the user presses cancel, I want to abort the thread started. I wrote the code as below:
private void btn_cancel_Click(object sender, RoutedEventArgs e)
{
if (thread.Name == "PDF")
thread.Abort();
}
But the thread doesn't abort and continues the process. Please give me your valuable suggestions.