C# - 18 - A better delegate for updating the UI

[C# 3.5]

The UI can only be changed by the UI thread. However, sometimes you have UI changes coming from other threads (for example from a timer event). Traditionally you might code something like this:

This will recursively call the method again using a delegate and passing the same data in.

The problem with this approach is you have to code multiple delegates (one for each method signature) and maintain them. A cleaner solution is …

The delegate is defined within the scope of the method that needs it, and doesn't have any parameters to be maintained in parallel to the method call itself. Simples.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License