关于跨线程访问控件

public partial class Form1 : Form
    
{
        
delegate void ChangeText();
        Thread s;
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void ChangeMyText()
        
{
            
if (textBox1.InvokeRequired)
            
{
                textBox1.BeginInvoke(
new ChangeText(ChangeMyText));
            }

            
else
            
{
                textBox1.Text 
+= "CD ";
            }

        }

        
private void Form1_Load(object sender, EventArgs e)
        
{
            s 
= new Thread(new ThreadStart(XX));
            s.Start();
            
            
        }

        
private void XX()
        
{
            Thread.Sleep(
10000);
            ChangeMyText();
        }

        
private void CallBack(IAsyncResult result)
        
{
 
        }

    }

最简单的办法就是直接修改最后的ChangeMyText方法,用异步调用自己就变成同步了。
posted @ 2008-03-06 09:21  zeus2  Views(238)  Comments(0Edit  收藏  举报