如题。
解决方案 »
- 如何获取PictureBox中的图片的路径(在线等!)
- DevExpress的GridControl的焦点设置问题,找了一天了,求大家帮助.
- 如何打造一个优秀的类?
- 用C#编写的一个播放器
- 遇到麻烦了.
- 线程挂起,在2005中该怎么做才好?
- 请问谁有C#的教学网站?我初学者,对什么便利之类都不知道
- 怎样用c#实现在发布应用程序时,将应用程序写到"开始"-"所有程序"里?
- 字符串匹配的问题
- 在Canvas上画画的时候如何同步播放笔和纸的摩擦音效
- 看似简单的问题:MyClass myClass = new MyClass(); 如何让myClass.Name等于"myClass"?
- 根据输入的计算式自动计算结果
using System.Threading;
using System.Collections.Generic;
using System.Windows.Forms;public class MyClass
{
public static void Main()
{
Application.Run(new FormMain());
}
public class FormMain :Form
{
Thread thread1;
Thread thread2;
Button buttonCloseThread1;
private void Thread1Method()
{
while(true)
{
Console.WriteLine("Thread 1 at:" + DateTime.Now);
Thread.Sleep(2000);
}
}
private void Thread2Method()
{
while(true)
{
Console.WriteLine("Thread 2 at:" + DateTime.Now);
Thread.Sleep(2000);
}
}
public FormMain()
{
thread1 = new Thread(new ThreadStart(Thread1Method));
thread2 = new Thread(new ThreadStart(Thread2Method));
thread1.Start();
thread2.Start();
this.buttonCloseThread1 = new Button();
this.buttonCloseThread1.Text = "Closed Thread 1";
this.Controls.Add(this.buttonCloseThread1);
this.buttonCloseThread1.Click += delegate{
if( thread1 != null )
thread1.Abort();
};
}
}
}
using System;
using System.Threading;
using System.Collections.Generic;
using System.Windows.Forms;public class MyClass
{
public static void Main()
{
Application.Run(new FormMain());
}
public class FormMain :Form
{
Thread thread1;
Thread thread2;
Button buttonCloseThread1;
private void Thread1Method()
{
while(true)
{
Console.WriteLine("Thread 1 at:" + DateTime.Now);
Thread.Sleep(2000);
}
}
private void Thread2Method()
{
while(true)
{
Console.WriteLine("Thread 2 at:" + DateTime.Now);
Thread.Sleep(2000);
}
}
public FormMain()
{
thread1 = new Thread(new ThreadStart(Thread1Method));
thread2 = new Thread(new ThreadStart(Thread2Method));
thread1.Start();
thread2.Start();
this.buttonCloseThread1 = new Button();
this.buttonCloseThread1.Text = "Closed Thread 1";
this.Controls.Add(this.buttonCloseThread1);
this.buttonCloseThread1.Click += delegate{
if( thread1 != null )
thread1.Abort();
};
}
}
}
static void run()
{
while (!flag)
{
Console.WriteLine("run");
Thread.Sleep(1000);
} }
Thread t = new Thread(run);
t.Start();
int i=0;
while (i<10)
{
Thread.Sleep(1000);
i++;
}
flag = true;
t.Join();
Console.WriteLine("Complete");
Console.Read();