public partial class LiemaiMan : Form
{
BackgroundWorker m_Worker;// 放在后台执行
// 用一个标记来看是否请求停止执行
bool m_NeedRun = false;
public LiemaiMan()
{
InitializeComponent();
m_Worker = new BackgroundWorker();
m_Worker.DoWork += new DoWorkEventHandler(m_Worker_DoWork);
}
private void m_Worker_DoWork(object sender, EventArgs e)
{
while (m_NeedRun)
for (int i = 1; i <= 12; i++)
{
Bgop.KeyPress(hwnd, 8);
}
//备份
System.Threading.Thread.Sleep(2000);
Clipboard.SetText(this.dataGridView1.Rows[x].Cells[0].Value.ToString());
//装弹
Bgop.PostMessage(hwnd, 770);
//恢复备份d
SendKeys.SendWait(“{TAB}”);
System.Type oType = System.Type.GetTypeFromProgID(“WScript.Shell”);
object o = System.Activator.CreateInstance(oType);
oType.InvokeMember(“SendKeys”, System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { this.dataGridView1.Rows[x].Cells[1].Value.ToString() });
oType.InvokeMember(“SendKeys”, System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] { “{ENTER}” });
}
private void button21_Click(object sender, EventArgs e)
{
m_NeedRun = true;
m_Worker.RunWorkerAsync();
}
private void button20_Click(object sender, EventArgs e)
{
m_NeedRun = false;
}
线程执行到 Clipboard.SetText(this.dataGridView1.Rows[x].Cells[0].Value.ToString());这句就提示在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main函数带有STAThreadAttribute标记。
见检查已经有[STAThread]
static void Main()
这该怎么解决啊?各位大侠帮忙看看