Cursor Wait bei rechenintensiven Aufgaben

Veröffentlicht von

Hier mal ein kleines Beispiel, wie man den Cursor auf Wait stellen kann, wenn man eine Methode hat, die sehr rechenintensiv ist

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace App.cursor
{
    public class OverrideCursor : IDisposable
    {
        static Stack<Cursor> s_Stack = new Stack<Cursor>();

        public OverrideCursor(Cursor changeToCursor)
        {
            s_Stack.Push(changeToCursor);

            if (Mouse.OverrideCursor != changeToCursor)
                Mouse.OverrideCursor = changeToCursor;
        }

        public void Dispose()
        {
            s_Stack.Pop();

            Cursor cursor = s_Stack.Count > 0 ? s_Stack.Peek() : null;

            if (cursor != Mouse.OverrideCursor)
                Mouse.OverrideCursor = cursor;
        }

    }
}Code-Sprache: HTML, XML (xml)
using (new OverrideCursor(Cursors.Wait))
{
    // eine Action
}Code-Sprache: JavaScript (javascript)