可以执行呀using System; using System.Threading; public class tclass { public tclass() { Thread R = new Thread(new ThreadStart(InUsrGame)); R.Start(); } static void InUsrGame() { Console.WriteLine("ok"); } } class A { static void Main() { tclass t=new tclass(); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Threading;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {
} private void button1_Click(object sender, EventArgs e) { tclass c = new tclass(); } } public class tclass { static tclass() { Thread R = new Thread(new ThreadStart(InUsrGame)); R.Start(); } public static void InUsrGame() { MessageBox.Show("只有第一次点击才会弹出提示框"); } } }
{
//do somthing
}
namespace xxx
{
public class tclass
{
static tclass()
{
Thread R = new Thread(new ThreadStart(InUsrGame));
R.Start();
}
}
}
{
MessageBox.Show("看看会不会报错");
}
我是记录日志log来查看,是否程序有进入但是没打印出来.
using System.Threading;
public class tclass
{
public tclass()
{
Thread R = new Thread(new ThreadStart(InUsrGame));
R.Start();
}
static void InUsrGame()
{
Console.WriteLine("ok");
}
}
class A
{
static void Main()
{
tclass t=new tclass();
Console.ReadLine();
}
}
不是控制台程序....只要有引用到tclass的一个方法
static tclass()
{
//刚开始都会执行...
}但 线程Thread所委托的方法,就是进不入...
把static void InUsrGame()修改为void InUsrGame()再测试
这个
static tclass()
{
//程序有走到这里来
}
我有个方法是记录日志的: command.addLog("xxxx");会有打印出日志出来
static void InUsrGame()
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
tclass c = new tclass();
}
} public class tclass
{
static tclass()
{
Thread R = new Thread(new ThreadStart(InUsrGame));
R.Start();
} public static void InUsrGame()
{
MessageBox.Show("只有第一次点击才会弹出提示框"); }
}
}
我之前都是像我上面那样在写代码的..都运行得好好的...
不知道这次为什么会这样..我还对比之前写的可以运行的代码,static class这部分是一模一样的..真郁闷了.