Error while trying to change cursor during C#algorithm

Asked

Viewed 71 times

1

Hello, I am developing a C# software to help in the scanning of old photos, and in the middle of one of the algorithms to process the images, I want the cursor to change to the loading mode so that the user knows when the system is processing.

What I did was insert this way right 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 thing 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

Details of the error:

{Function Evaluation disabled because a Previous Function Evaluation timed out. You must continue Execution to reenable Function Evaluation.}

Is the command wrong? Any idea how to proceed?

  • With this code you can not see any error. Post where the error actually occurs.

  • Sorry, the error comes directly from line "this. Cursor = Cursors.Wait;"

  • What technology are you using?

  • What do you mean, technology? For interface? It’s C# WPF

2 answers

1


By chance you are stirring other threads to do parallel processing?

I suggest putting this around the cursor command:

this.Dispatcher.Invoke(new Action(() =>
        {
            this.Cursor = Cursors.Wait;
        }));
  • Thanks rafascar!! It worked yes, but Voce knows if it is the most suitable method? does not give any unfavorable delay?

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 cursor receives something will change in bindind as well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.