Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class FormMain : Form
- {
- public static FormMain EventSend;
- public FormMain()
- {
- InitializeComponent();
- EventSend = this;
- }
- public void AppendMessage(string value)
- {
- if (InvokeRequired)
- {
- this.Invoke(new Action<string>(AppendMessage), new object[] { value });
- return;
- }
- listBox1.Items.Add(value);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Thread thread = new Thread(ForThread.DoIt);
- thread.Start();
- }
- }
- class ForThread
- {
- private static void SendMessage(string value)
- {
- FormMain.EventSend.AppendMessage(value);
- }
- public static void DoIt()
- {
- // тут появляется магия вашего потока и генерируются names,
- // а для примера:
- for (int i = 1; i <= 5; i++)
- {
- string names = i.ToString();
- // И на всякий случай
- if (names != null)
- {
- SendMessage(names);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement