多线程/调用的问题:(

时间:2011-01-22 19:04:28

标签: c#

我有2个脚本1- Soket.cs(Soket Server使用线程)FormMain.cs(Working Normal)我使用以下代码从soket.cs调用FormMain中的函数:

public void ResiveFunc(string FuncResive)
{


    string FuncName = "";
    string FuncValue = "";
    for (int i = 0; i <= 2; i++)
    {
        FuncName += FuncResive[i];
    }
    for (int j = 4; j <= FuncResive.Length - 1; j++)
    {
        FuncValue += FuncResive[j];
    }
    MessageBox.Show(FuncName);
    MessageBox.Show(FuncValue);
    if (FuncName == "TAB")
    {
        Form1 mainForm = new Form1();
        mainForm.AdverFilter(FuncValue);
    }

}

我在FormMain中调用这个AdverFilter()函数:

  public void AdverFilter(string value)
    {
        if (this.InvokeRequired)
        {

            this.BeginInvoke(new Action<string>(AdverFilter),value);
        }
        else
        {
            this.richTextBox1.Text = value;
            MessageBox.Show("AdverFilter(string value)");
            MessageBox.Show(this.richTextBox1.Text);
        }

    }

但它不起作用! Messagebox显示值很好但在GUI中richtextbox.text为空(在函数结束后)...请告诉我如何解决这个问题......!

1 个答案:

答案 0 :(得分:0)

发送字符串clone:

mainForm.AdverFilter(FuncValue.Clone());

this.BeginInvoke(new Action<string>(AdverFilter),value.Clone());