Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void SetText(string cntName,string msg)
- {
- if (this.InvokeRequired)
- {
- //Invoke(new SetTextCallback(SetText), new object[] { cntName }, new object[] { msg });
- Invoke(new SetTextCallback(SetText), cntName , msg );
- return;
- }
- switch (cntName)
- {
- case shareData.Control.button1:
- break;
- case shareData.Control.button2:
- break;
- case shareData.Control.button3:
- break;
- case shareData.Control.button4:
- break;
- case shareData.Control.button5:
- break;
- case shareData.Control.button6:
- break;
- case shareData.Control.button7:
- break;
- case shareData.Control.button8:
- break;
- case shareData.Control.button9:
- break;
- case shareData.Control.button12:
- break;
- case shareData.Control.textBox1:
- textBox1.Text = (msg);
- break;
- case shareData.Control.textBox2:
- textBox2.AppendText(msg);
- break;
- default:
- break;
- }
- }
- private void Form1_Shown(object sender, EventArgs e)
- {
- workerThread t = new workerThread(SetText);
- t.Start();
- }
- }
- }
- public class shareData
- {
- public struct Control
- {
- public const string textBox1 = "textBox1";
- public const string textBox2 = "textBox2";
- public const string label1 = "label1";
- public const string label2 = "label2";
- public const string label3 = "label3";
- public const string label4 = "label4";
- public const string label5 = "label5";
- public const string label6 = "label6";
- public const string label7 = "label7";
- public const string label8 = "label8";
- public const string button1 = "button1";
- public const string button2 = "button2";
- public const string button3 = "button3";
- public const string button4 = "button4";
- public const string button5 = "button5";
- public const string button6 = "button6";
- public const string button7 = "button7";
- public const string button8 = "button8";
- public const string button9 = "button9";
- public const string button12 = "button12";
- public const string listView1 = "listView1";
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace WindowsFormsApplication1
- {
- delegate void SetTextCallback(string cntName, string msg);
- class workerThread
- {
- SetTextCallback _SetText;
- int TID;
- public workerThread(SetTextCallback SetText)
- {
- _SetText = SetText;
- TID = 0;
- }
- Thread t;
- public void Start()
- {
- t = new Thread(new ThreadStart(worker));
- t.Start();
- }
- void worker()
- {
- int tid = TID;
- TID++;
- for (int i = 0; i < 100; i++)
- {
- _SetText(shareData.Control.textBox1, i.ToString());
- _SetText(shareData.Control.textBox2, i.ToString());
- System.Threading.Thread.Sleep(1000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement