Autor Beitrag
ebber
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Mo 17.03.08 01:29 
Hallo

ich bekomme diese Fehlermeldung wenn ich textBox1.Text verändern will.

Additional information: Ungültiger threadübergreifender Vorgang: Der Zugriff auf das Steuerelement Form1 erfolgte von einem anderen Thread als dem Thread, für den es erstellt wurde.

Ich habe etwas über Invoke gelesen, was dieses Problem verhindern soll? Ich bin aber nicht so ganz dahinter gekommen wie ich das benutze. Kann mir da jemand helfen, bitte?

MfG
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4795
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 17.03.08 10:47 
siehe z.B. hier www.mycsharp.de/wbb2...d.php?threadid=33113
oder hier www.yoda.arachsys.co...reads/winforms.shtml.

Ansonsten such einfach mal nach "Invoke Thread".
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Mo 17.03.08 23:42 
Danke. Das hat mein Problem gelöst.

MfG
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Di 18.03.08 15:40 
... dachte ich zumindest. Leider ist das nur die halbe Wahrheit.

So funktioniert das jetzt zwar,

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
        void AccessToTB()
        {
            if (textBox1.InvokeRequired)
            {
                textBox1.Invoke(new MethodInvoker(AccessToTB));
                return;
            }
            textBox1.Text = textBox1.Text + "\r\n" + "xyz";
        }


aber ich möchte der Funktion gerne noch einen Parameter übergeben. Also statt dem "xyz" einen Text über einen Parameter.
Kann mir da jemand bitte weiterhelfen ?

MfG
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4795
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 18.03.08 17:33 
Hier das Beispiel aus meinem 2. Link:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
delegate void StringParameterDelegate (string value);

void UpdateStatus(string value)
    {
        if (InvokeRequired)
        {
            // We're not in the UI thread, so we need to call BeginInvoke
            BeginInvoke(new StringParameterDelegate(UpdateStatus), new object[]{value});
            return;
        }
        // Must be on the UI thread if we've got this far
        statusIndicator.Text = value;
    }

d.h. du mußt statt dem Standard MethodInvoker nur einen eigenen Delegate erstellen.
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Mi 19.03.08 11:59 
Oh, das muss ich wohl überlesen haben.
Aber danke, es funktioniert.

MfG