Alternative zu CheckForIllegalCrossThreadCalls

06/27/2013 22:11 Requi#1
Bin ja nicht gerade der beste was .net angeht :D

Habt ihr eine alternative?
Google konnte da nix gutes ausspucken.

MfG
06/27/2013 22:38 dready#2
Bisschen wenig Infos was genau du wissen magst ;)

Denk mal das hier ?

[Only registered and activated users can see links. Click Here To Register...]
06/27/2013 22:59 'Aleo#3
Ob es eine echte Alternative weiß ich jetzt nicht, aber wenn du willst kannst du dir gerne Delegates/Invokes anschauen. Einfach mal googeln.
06/27/2013 23:10 dready#4
@Aleo wenn ichs rechtig im Kopf hab ist eines der Beispiele im Msdn genau das :)

Für Guigedönse benutz ich gern diesen Oneliner

Code:
 void Bla()
    {
        if (InvokeRequired) { Invoke(new Action(bla)); return; }
//nix
    }
06/28/2013 09:27 »Barney«#5
Code:
if (this.InvokeRequired)
     this.Invoke(new MethodInvoker(() => this.textBox1.Text = "Thread Safe"));
else
     this.textBox1.Text = "Already on the UI thread";
I hope this is what you asked
06/28/2013 12:32 Cholik#6
[Only registered and activated users can see links. Click Here To Register...]
07/01/2013 05:00 »jD«#7
dready and chichi are correct. If the control isn't owned by the thread the function is called on, you will need to invoke it.

-jD
07/01/2013 10:35 Cholik#8
You don't have to invoke when using the Backgroundworker Class... why should you choose that class if you're going to invoke anyway?

Just read my link... When using Backgroundworker you can use the ReportProgress Event which is executed in the context of the UI thread, so you don't have to invoke anything.


Und nochmal auf deutsch:
Wenn man den Backgroundworker nutzt braucht man nicht zu invoken, wie ich schon 4 Mal geschrieben habe, aber keiner scheints zu lesen. Das ist ja das tolle am Backgroundworker, man muss nix mehr invoken. Einfach die Events der Klasse nutzen (z.B. ReportProgress) welche im Kontext des UI-Threads ausgeführt werden. Wenn man so oder so invoken WILL braucht man auch nicht die Backgroundworker Klasse nutzen.

[Only registered and activated users can see links. Click Here To Register...]

[Only registered and activated users can see links. Click Here To Register...]
07/01/2013 11:34 dready#9
Ofcourse you dont have to invoke if you use a Backgroundworker, but Requi mentioned in the last thread that he dont like Background workers so i guessed he wished to know an Invoke example.

The Msdn Example about threadsave working with the GUI has an example about using a Backgroundworker too.
07/01/2013 14:56 »jD«#10
Background workers are being deprecated in preference of the TPL, ThreadPool, and async/await anyway.

-jD