C#: Chaîne de caractères comme paramètre de l'événement?

J'ai une interface graphique-thread pour mon formulaire et un autre thread qui calcule les choses.

La forme a un richtTextBox. Je veux que le travailleur-fil pour passer des chaînes de la forme, de sorte que chaque chaîne est affichée dans la zone de texte.

À chaque fois une nouvelle chaîne est généré dans le thread que j'appelle un événement, et cela devrait maintenant afficher la chaîne.
Mais je ne sais pas comment faire pour passer à la chaîne! C'est ce que j'ai essayé jusqu'à présent:

/////Form1
private void btn_myClass_Click(object sender, EventArgs e)
{
    myClass myObj = new myClass();
    myObj.NewListEntry += myObj_NewListEntry;
    Thread thrmyClass = new Thread(new ThreadStart(myObj.ThreadMethod));
    thrmyClass.Start();
}

private void myObj_NewListEntry(Object objSender, EventArgs e)
{
    this.BeginInvoke((MethodInvoker)delegate
    {
        //Here I want to add my string from the worker-thread to the textbox!
        richTextBox1.Text += "TEXT"; //I want: richTextBox1.Text += myStringFromWorkerThread;
    });
}

/////myClass (working thread...)
class myClass
{
    public event EventHandler NewListEntry;

    public void ThreadMethod()
    {
        DoSomething();
    }

    protected virtual void OnNewListEntry(EventArgs e)
    {
        EventHandler newListEntry = NewListEntry;
        if (newListEntry != null)
        {
            newListEntry(this, e);
        }
    }

    private void DoSomething()
    {
        /////Do some things and generate strings, such as "test"...
        string test = "test";


        //Here I want to pass the "test"-string! But how to do that??
        OnNewListEntry(EventArgs.Empty); //I want: OnNewListEntry(test);
    }
}
Sous-classe EventArgs et ajouter votre chaîne de propriété.

OriginalL'auteur think | 2012-08-21