Why is this method executing twice each time I call it?

Posted by highone on Stack Overflow See other posts from Stack Overflow or by highone
Published on 2010-04-15T20:45:17Z Indexed on 2010/04/15 20:53 UTC
Read the original article Hit count: 350

Filed under:
|
|

I have the following method that is executing twice every time it is called:

public static void ChangeToRepository(RepositoryTextBox textBox, int repositoryNumber)
    {
        MessageBox.Show("you");
        int indexOfLastRepository = (textBox.RepositoryCollection.Count - 1);
        if (repositoryNumber > indexOfLastRepository)
        {
            AddTextRepositoriesThrough(textBox, repositoryNumber, indexOfLastRepository);
        }
        textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText = textBox.Text;
        textBox.PreviousRepositoryNumber = textBox.CurrentRepositoryNumber;
        textBox.CurrentRepositoryNumber = repositoryNumber;
        textBox.Text = textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText;
    }

The first time that the method executes, it executes all of the code except for its last line:

textBox.Text = textBox.RepositoryCollection[textBox.CurrentRepositoryNumber].CurrentText;

The second time, it executes all of the code. What's up?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#4.0