Browsed by
Schlagwort: Threading

ThreadPool.QueueUserWorkItem vs Thread.Start (Vergleich der Ausführungsgeschwindigkeit)

ThreadPool.QueueUserWorkItem vs Thread.Start (Vergleich der Ausführungsgeschwindigkeit)

Im Rahmen der Optimierung der Laufzeit einer Anwendung stolperte ich über einen in der Praxis recht oft vorkommenden Fall. Der Profiler zeigte (nach langem Konfigurieren und Suchen dank der schlechten Dokumentation des mäßigen Profilers im Visual Studio 2008 TS) eine bestimmte recht kostenintensive I/O-Funktion, die oft aufgerufen wird. Klarer Fall: so etwas läßt sich einfach durch Parallelisierung optimieren.

Mehr lesen Mehr lesen

Accessing a WinForm/WPF control from another thread through invoke

Accessing a WinForm/WPF control from another thread through invoke

A pretty common scenario: you have some time-consuming calculation to do (or some other requirements giving the necessity for multithreading), so from your main GUI, you start a worker thread (since then your GUI stays nice and responsive, even though now one of the problems you face is preventing your user from doing things he should not be doing while the thread runs). Since the procedure is so long, you maybe want to update a status label in the main window, or at least you want to set some result string when the thread is finished.

Good idea. But.. if you do it in a straightforward way (calling into your class with a static variable of sorts), your application will throw an exception in debug mode and might (very occasionally) cause trouble in release mode (if there are problems with concurrent access – since WinForms as well as WPF is not created for concurrency).

Fortunately, there is a solution.

Mehr lesen Mehr lesen