File tree Expand file tree Collapse file tree
CefSharp.MinimalExample.WinForms/Controls Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88namespace CefSharp . MinimalExample . WinForms . Controls
99{
10- public static class ControlExtensions
11- {
12- /// <summary>
13- /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
14- /// </summary>
15- /// <param name="control">the control for which the update is required</param>
16- /// <param name="action">action to be performed on the control</param>
17- public static void InvokeOnUiThreadIfRequired ( this Control control , Action action )
18- {
19- if ( control . InvokeRequired )
20- {
21- control . BeginInvoke ( action ) ;
22- }
23- else
24- {
25- action . Invoke ( ) ;
26- }
27- }
28- }
10+ public static class ControlExtensions
11+ {
12+ /// <summary>
13+ /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
14+ /// </summary>
15+ /// <param name="control">the control for which the update is required</param>
16+ /// <param name="action">action to be performed on the control</param>
17+ public static void InvokeOnUiThreadIfRequired ( this Control control , Action action )
18+ {
19+ //If you are planning on using a similar function in your own code then please be sure to
20+ //have a quick read over https://stackoverflow.com/questions/1874728/avoid-calling-invoke-when-the-control-is-disposed
21+ //No action
22+ if ( control . Disposing || control . IsDisposed || ! control . IsHandleCreated )
23+ {
24+ return ;
25+ }
26+
27+ if ( control . InvokeRequired )
28+ {
29+ control . BeginInvoke ( action ) ;
30+ }
31+ else
32+ {
33+ action . Invoke ( ) ;
34+ }
35+ }
36+ }
2937}
You can’t perform that action at this time.
0 commit comments