First of all you need to declare a form level BackGroundWorker, and in your form constructor add a handler for it's DoWork event. Then you can simply run your above code in the DoWork event, something like this:
BackgroundWorker bgw = new BackgroundWorker();
public Form1()
{
InitializeComponent();
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
button1.Click += new EventHandler(button1_Click);
}
void button1_Click(object sender, EventArgs e)
{
bgw.RunWorkerAsync();
}
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
if(cmbSelectFileType.Text == "Text")
{
if (Validation())
{
panel1.Enabled = false;
pictureBox1.Visible = true;
UpLoadUsingText();
}
}
else if (cmbSelectFileType.Text == "Excel")
{
if (Validation())
{
panel1.Enabled = false;
pictureBox1.Visible = true;
UpLoadUsingExcel();
}
}
}
Hope this helps