I have a problem implementing code i got from stackowerflow its about killing a backgroundworker process.
My code is as follows:
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using GluthGUI.Classes.XMLprofile;
using System.Xml.Linq;
using System.ComponentModel;
namespace Solution
{
partial class SolGUI : Form
{
private void startButton_Click(object sender, EventArgs e)
{
backgroundWorker1 = new AbortableBackgroundWorker();
if (startButton.Text == "Start")
{
XMLParsing();
DisableTextFields();
backgroundWorker1.RunWorkerAsync();
startButton.Text = "Stop";
}
else if (startButton.Text == "Stop")
{
if (backgroundWorker1.IsBusy == true)
{
backgroundWorker1.Abort(); //error Abort() is not declared?!?!
backgroundWorker1.Dispose();
}
startButton.Text = "Start";
DisableTextFields();
}
}
}
This is a partial class which would terminate backgroundworker:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Threading;
namespace Solution
{
public class AbortableBackgroundWorker : BackgroundWorker
{
private Thread workerThread;
protected override void OnDoWork(DoWorkEventArgs e)
{
workerThread = Thread.CurrentThread;
try
{
base.OnDoWork(e);
}
catch (ThreadAbortException)
{
e.Cancel = true; //We must set Cancel property to true!
Thread.ResetAbort(); //Prevents ThreadAbortException propagation
}
}
public void Abort()
{
if (workerThread != null)
{
workerThread.Abort();
workerThread = null;
}
}
}
}
My problem is that Abort() method from partial class is not visible in other classes with same namespace.