How to display Busy cursor for x number of time then a splash screen?

287 Views Asked by At

I have application in WPF with C#.net in which we have lot of expensive operations. Recently we got this requirement: For long running processes display the busy cursor till 3 seconds, if operation is exceeding 3 second display the splash screen until operation is finished. I have searched a lot over the net but nothing seems to be relevant. Any support will be high appreciated.

We have tried something, it works but in few case it is not giving expected results. Any help would be highly appreciated. When my internal logic display any alert message and wait for the user input, Busy Cursor function timer keep running, we got the splash too.

    public class BusyCursor:IDisposable
    {
        private Cursor _previousCursor;
        System.Timers.Timer _timer     
        public BusyCursor()
        {
            _previousCursor = Mouse.OverrideCursor;
            Mouse.OverrideCursor = Cursors.Wait;
           _timer = new System.Timers.Timer(); 
           _timer.Interval = 3000;
           _timer.Elapsed += timer_Tick;
           _timer.Start();
        }
        public void timer_Tick(object sender, ElapsedEventArgs e)
        {           
            Application.Current.Dispatcher.Invoke((new Action(() =>
                {
                    if (!DXSplashScreen.IsActive)
                    {
                        DXSplashScreen.Show<TrippsSplashScreen>();
                    }
                    Mouse.OverrideCursor = Cursors.Arrow;
                    _timer.Stop();

                })), DispatcherPriority.ApplicationIdle);            

        }
        #region IDisposable Members
        public void Dispose()
        {            
                _timer.Stop();
                if (DXSplashScreen.IsActive)
                {
                    DXSplashScreen.Close();
                }
                Mouse.OverrideCursor = Cursors.Arrow;               
        }
        #endregion
    }

Usage:

using (new BusyCursor())
{
       //logic ---
}

Thanks

1

There are 1 best solutions below

5
On
bool calculating = false;
bool showingSplash = false;
void Meth(Task[] expensiveCalls)
{
    Task.Factory.StartNew(() =>
    {
        calculating = true;
        Task.Factory.StartNew(() =>
        {
            Task.Delay(3000).Wait();
            if (calculating)
            {
                showingSplash = true;
                //Application.Current.Dispatcher.Invoke(() => show_sphlash());
            }
        });
        Task.WaitAll(expensiveCalls);
        calculating = false;
        if (showingSplash)
        {
            //Application.Current.Dispatcher.Invoke(() => hide_sphlash());
            showingSplash = false;
        }
    }
    );
}