Method | Description | |
---|---|---|
Invoke ( string nameForErrorReporting, |
Invoke and action safely even if called from the background thread. Invoking on the ui thread from background threads works *most* of the time, with occasional crash. Stackoverflow has a good collection of people trying to deal with these corner cases, where InvokeRequired(), for example, is unreliable (it doesn't tell you if the control hasn't even got a handle yet). SIL.Core (lipalaso) has a SafeInvoke on its LogBox control, which sees heavy background/foreground interaction and seems to work well over the course of years. I think I (JH) wrote that, but it relies on a couple of odd things: 1) it calls IsHandleCreated() (which can reportedly create the handle on the wrong thread?) and 2) uses SynchronizationContext which works for that single control case but I'm not seeing how to generalize that. So now I'm trying something more mainstream here, from a highly voted SO answer. |
|
InvokeIfPossible ( string nameForErrorReporting, |
This version just makes it clear that the call is permissive, won't bother the user if something goes wrong, which is appropriate for many background-->foreground ui tasks, like refreshing.
|
public static Invoke ( string nameForErrorReporting, |
||
nameForErrorReporting | string | |
control | ||
forceSynchronous | bool | |
throwIfAnythingGoesWrong | bool | |
action | System.Action | |
return | void |
public static InvokeIfPossible ( string nameForErrorReporting, |
||
nameForErrorReporting | string | |
control | ||
forceSynchronous | bool | |
action | System.Action | |
return | void |