我正在使用此代码
Thread T = new Thread(new ThreadStart(Listen));
T.IsBackground = true;
T.Start();
它返回这些错误;
[第2行]类,结构或接口成员声明中的标记'='无效 [第3行]无效的令牌'('在类,结构或接口成员声明中
有人可以了解这里出了什么问题,因为我真的不知道是什么。
答案 0 :(得分:4)
你在一个类中写了这3行,而不是在该类的方法中。
这会产生错误:
public class Dummy
{
Thread T = new Thread(new ThreadStart(Listen));
T.IsBackground = true;
T.Start();
...
}
这不会:
public class Dummy
{
public void Test()
{
Thread T = new Thread(new ThreadStart(Listen));
T.IsBackground = true;
T.Start();
}
...
}