I am having an issue with backgroundworker in c#. I am coding a dll file.
This is my code in a Class Library (.NET Framework) type project within VS 2019:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace States
{
public class ST
{
public static void Read()
{
BackgroundWorker bgwMessage = new BackgroundWorker();
bgwMessage.DoWork += new DoWorkEventHandler(BgwFileOpen_DoWork);
bgwMessage.RunWorkerAsync();
}
private static void BgwFileOpen_DoWork(object sender, DoWorkEventArgs e)
{
MessageBox.Show("Ran");
}
}
}
When I call the Read()
method using the Immediate window the command in background worker's DoWork
method does not run. Debguging the problem line by line shows that the Read()
method is running but it does not call RunworkerAsync somehow.
*Update1: starting a thread also did not work either:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TradeStates
{
public class ST
{
public static void Read()
{
Thread thr = new Thread(new ThreadStart(MSGshow));
thr.Start();
}
public static void MSGshow()
{
MessageBox.Show("Ran");
}
}
}