Error when trying to change cursor during algorithm C #

1

Hello, I'm developing C # software to help digitize old photos, and in the middle of one of the algorithms to process the images, I want the cursor to switch to loading mode so the user knows when the system is processing. >

What I did was insert this way at the beginning of the function:

        this.Cursor = Cursors.Wait;

        int count = 0;
        int n = System.IO.Directory.GetFiles(path, "*.jpg", System.IO.SearchOption.AllDirectories).Length;

        foreach (string file in System.IO.Directory.GetFiles(path, "*.jpg", System.IO.SearchOption.AllDirectories))
        {
            MotherImage mImage = new MotherImage(file);
            mImage.targetImage.CalculateDataIntensity();
            mImage.CreateMap();

           ...

The only however is that I get this error message from Visual Studio:

Error message:

  

An exception of type 'System.InvalidOperationException' occurred in   WindowsBase.dll but was not handled in user code

Error Details:

  

{Function evaluation disabled because of a previous function evaluation   timed out You must continue execution to reenable function   evaluation.}

Is the command wrong? Any ideas on how to proceed?

    
asked by anonymous 17.03.2016 / 22:20

2 answers

0

Are you currently tinkering with other threads to do parallel processing?

I suggest putting this around the cursor command:

this.Dispatcher.Invoke(new Action(() =>
        {
            this.Cursor = Cursors.Wait;
        }));
    
17.03.2016 / 22:30
0

I think you should use binding ...

no .xaml

 Cursor="{Binding cursor}"

no .cs

 private Cursor _cursor;   
 public Cursor cursor
    {
        get { return _cursor; }
        set
        {
            _cursor = value;
            OnPropertyChanged("cursor");
        }
    }

So every time the cursor receives something it will change in bindind too.

    
10.08.2017 / 19:45