JD2022-TU1/main/tools/framework/JD.Threading/Dispatch/DefaultMessageLoop.cs

45 lines
1,015 B
C#

using System.Threading;
namespace JD.Threading.Dispatch
{
/// <summary>
/// Must be created on the UI thread that it is supposed to represent.
/// </summary>
internal class DefaultMessageLoop : IMessageLoop
{
#region Variables
private readonly WindowsFormsThreadDispatchStrategy m_underlyingStrategy = new WindowsFormsThreadDispatchStrategy();
#endregion
#region Properties
public bool InvokeRequired
{
get { return m_underlyingStrategy.InvokeRequired; }
}
#endregion
#region Methods
public void Invoke(System.Action action)
{
m_underlyingStrategy.Dispatch(action);
}
public void BeginInvoke(System.Action action)
{
m_underlyingStrategy.DispatchAsync(action, true);
}
public void WaitAndPump(WaitHandle waitHandle)
{
Win32MessageLoop.WaitAndPump(waitHandle);
}
#endregion
}
}