|
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 test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Invoke does not work without the control
// handle first being created. Since I am
// starting the worker threads in the constructor,
// I have to force creation of this handle early.
// Remove this code and see what happens!
while (!IsHandleCreated)
{
// force handle creation
IntPtr temp = Handle;
}
ThreadPool.QueueUserWorkItem(Foo);
ThreadPool.QueueUserWorkItem(Foo);
ThreadPool.QueueUserWorkItem(Foo);
}
public void Foo(object o)
{
while (true)
{
rtb.Invoke(new StringDelegate(UpdateDisplay),
new object[] { "Foo!\n" });
//Thread.Sleep(10);
}
}
public void UpdateDisplay(string text)
{
this.rtb.Text += text;
}
public delegate void StringDelegate(string foo);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Will Sullivan is a full time C# programmer in Columbia, SC. He enjoys sticking his finger through his right nostril and out his left tear duct. In photoshop.