WinForms - Add some extra Dispose checks to InvokeOnUiThreadIfRequired
Also added stackoverflow link regarding calling after the control has been disposed
This commit is contained in:
parent
0d386bf7b5
commit
fcbdda0964
@ -7,23 +7,31 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace CefSharp.MinimalExample.WinForms.Controls
|
namespace CefSharp.MinimalExample.WinForms.Controls
|
||||||
{
|
{
|
||||||
public static class ControlExtensions
|
public static class ControlExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
|
/// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="control">the control for which the update is required</param>
|
/// <param name="control">the control for which the update is required</param>
|
||||||
/// <param name="action">action to be performed on the control</param>
|
/// <param name="action">action to be performed on the control</param>
|
||||||
public static void InvokeOnUiThreadIfRequired(this Control control, Action action)
|
public static void InvokeOnUiThreadIfRequired(this Control control, Action action)
|
||||||
{
|
{
|
||||||
if (control.InvokeRequired)
|
//If you are planning on using a similar function in your own code then please be sure to
|
||||||
{
|
//have a quick read over https://stackoverflow.com/questions/1874728/avoid-calling-invoke-when-the-control-is-disposed
|
||||||
control.BeginInvoke(action);
|
//No action
|
||||||
}
|
if (control.Disposing || control.IsDisposed || !control.IsHandleCreated)
|
||||||
else
|
{
|
||||||
{
|
return;
|
||||||
action.Invoke();
|
}
|
||||||
}
|
|
||||||
}
|
if (control.InvokeRequired)
|
||||||
}
|
{
|
||||||
|
control.BeginInvoke(action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
action.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user