Xamarin simultaneously updating multiple class instances

Hi, I'm new to Xamarin and am making a Sudoku app.
I have a Board class that I create 2 instances of, 1 to solve the board to find the solution, and another to allow the user to solve. When I run my logic function that solves one of the boards, it somehow solves the other instance too, even with no mention of the other board in that class file. Initialising the board the user solves after the other one is already solved yields the same result, and my app always starts with a solved board. Any ideas? Cheers.

Best Answer

Answers

  • RavinderJangraRavinderJangra USMember ✭✭✭

    @calstr1 because you are referencing the both instances to the same space/memory. create and initialize them independently.

  • NMackayNMackay GBInsider, University ✭✭✭✭✭
    edited September 25

    @calstr1

    How are you binding to the models? there's little or no details to go on in your description of the problem. If your new to data binding you could have as issue that's not immediately obvious.

  • calstr1calstr1 NZMember

    @RavinderJangra said:
    @calstr1 because you are referencing the both instances to the same space/memory. create and initialize them independently.

    That sounds like that is the case. I created my instances in separate classes with
    Board Unsolved = new Board();
    Board Solved = new Board();
    Is that not the correct way to do so?

    My guess is that running functions of the Board class, update the board arrays in both instances at the same time.

    @NMackay said:
    @calstr1

    How are you binding to the models? there's little or no details to go on in your description of the problem. If your new to data binding you could have as issue that's not immediately obvious.

    I haven't used data binding, I assumed I was asking a generic question being "How do I stop method calls on one class instance from running on all instances?" but I think I may have made a hash of the post or that may not be what I asked. I'm not sure what other details to provide?

  • calstr1calstr1 NZMember
    edited September 27

    @RavinderJangra said:
    @calstr1 please check for static functions and values too. that might generate a problem like this.

    nothing in the Board class is static, just realized I am creating static instances, any chance that could be the problem? Cant get the rest of my code to work without the Board instances being static.

    Thank you very much for your help

  • NMackayNMackay GBInsider, University ✭✭✭✭✭

    @calstr1

    I just wanted to double check it wasn't a binding issue, that's all I wanted to clarify (as it is a lot of the time in Forms problems).

    The static references are probably your issue as suggested.

Sign In or Register to comment.