IsBusy should be a boolean or an int?

clopezclopez ✭✭✭ESMember ✭✭✭

Hello there!

I'm solving a lot of issues thanks to you, and learning many thinks.
But I was wondering if the variable IsBusy, that binding property all we use to notify the user that a background task is taking place, should be a boolean as I see in all codes, or an integer.
I'm worry about the fact that we set it from independent threads, and if they work as they teached me, if I call some commands with this structure:

 IsBusy = true;
 MyCommand.ChangeCanExecute();

 data = await GetData();

 IsBusy = false;
 MyCommand.ChangeCanExecute();

the first thread that ends will put "IsBusy" to false, while the others are still working, isn't it?
So it has sense to set IsBusy as an int, increment it when a new task is called, and decrement it if the task ends, and use a Converter to return true id IsBusy > 0.

Am I right, or did I miss something? What do you think?

Best Answer

Answers

  • clopezclopez ✭✭✭ ESMember ✭✭✭

    Yes, it makes perfect sense, but for one detail: I though that you said that conversions must be done with Converters!

    Just joking (too early in the morning). Yes, is a perfect solution so I don't have to change anything in the code, but the IsBusy logic, and I still get that variable as a bool as all the tutorials and programs use.
    I don't know if I'm doing things in the wrong way, or why is not used this way. It should had given problems to someone before, isn't it?

Sign In or Register to comment.