c#为我们提供thread可以这么用:
Thread t = new Thread(new ThreadStart(ScreenMonitor));
t.Start();
public void ScreenMonitor()
{
//操作
}
如果想在方法中传入参数怎么办?并且还不止一个参数!
struct ImageParam { public int a; public int b; public int c; public int d; } public void ScreenMonitor(Object args) { para = (ImageParam)args; int aa = para.a; int bb = para.b; int cc = para.c; int dd = para.d; Bitmap myImage = new Bitmap(aa, bb); Graphics g = Graphics.FromImage(myImage); g.CopyFromScreen(new Point(cc, dd), new Point(0, 0), new Size(aa, bb)); String picpath = @"d:\test.jpg"; myImage.Save(picpath); g.Dispose(); myImage.Dispose(); } private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(ScreenMonitor); ImageParam imgPara = new ImageParam(); imgPara.a = aa; imgPara.b = bb; imgPara.c = cc; imgPara.d = dd; t.Start((ImageParam)imgPara); }