【发布时间】:2014-02-20 09:05:21
【问题描述】:
我正在尝试编写一个简单的工具(它只包含一个类),但我坚持使用线程。 我不知道如何使用非静态方法运行线程。
我的windows窗体代码是这样的:
public partial class Form1 : Form
{
//--Some methods here--//
void login();
void start();
void refresh();
//--Button events--//
private void button1_Click()
{
//I want to start thread here
//Something like Thread t = new Thread(new ThreadStart(refresh));
//t.Start();
}
}
有了定时器,这个线程应该每 x 秒调用一次 refresh(),但定时器不是问题。 我收到线程错误:
A field initializer cannot reference the non-static field, method, or property.
【问题讨论】:
-
你没有发布产生这个编译错误的代码。
标签: c# multithreading