1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Threads
{
public partial class Form1 : Form
{
private delegate void EditBoxDelegateHandler(string str);
private EditBoxDelegateHandler EditBoxDelegate;
public Form1()
{
EditBoxDelegate = new EditBoxDelegateHandler(UpdateEditBox);
InitializeComponent();
Thread monThread = new Thread(new ThreadStart(ThreadProcess));
monThread.Start();
}
private void UpdateEditBox(string str)
{
textBox1.Text = str;
}
private void ThreadProcess()
{
while (true)
{
Invoke(EditBoxDelegate, textBox2.Text);
Thread.Sleep(1000);
}
}
}
} |