日期:2014-05-20 浏览次数:21074 次
MDI父
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WhyThread
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 f = new Form2(this);
f.Show();
}
}
}
子窗口
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WhyThread
{
public partial class Form2 : Form
{
Thread[] threads;
public Form2(Form1 parent)
{
InitializeComponent();
MdiParent = parent;
}
private void Form2_Load(object sender, EventArgs e)
{
}
void Do()
{
richTextBox1.Text += DateTime.Now.ToString();
}
void ThreadProc(Object obj)
{
(obj as Form2).Do();
}
private void button1_Click(object sender, EventArgs e)
{
threads = new Thread[100];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread(ThreadProc);
threads[i].IsBackground = true;
threads[i].Start(this);
}
}
}
}