using System;
using System.Windows.Input;
using System.Windows.Threading;

namespace Valg.EVA.Skanning.Assets.UIHelpers
{
    public class WaitCursor : IWaitCursor
    {
        private readonly Cursor _previousCursor;

        public WaitCursor()
        {
            _previousCursor = Mouse.OverrideCursor;
            Mouse.OverrideCursor = Cursors.Wait;
        }

        public void Dispose()
        {
            WaitForGuiRendering();

            Mouse.OverrideCursor = _previousCursor;
        }

        private static void WaitForGuiRendering()
        {
            
            Dispatcher.CurrentDispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
        }
    }
}
