我想写一个简单的工具(它只包含一个类),但我坚持线程。 我不知道如何使用非静态方法运行线程。线程使用非静态方法
我的窗户形式的代码是类似的东西:
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秒,但计时器心不是问题。 我收到提示螺纹:
A field initializer cannot reference the non-static field, method, or property.
你没有贴生成此编译错误的代码。 –
看这里http://stackoverflow.com/questions/7400677/a-field-initializer-cannot-reference-the-non-static-field-method-or-property –