views:

128

answers:

1

I have some code that starts a background process for search in my WPF application:

 private void RunSearch(SearchArguments arguments)
    {
        _getSearchResults.DoWork += GetSarchFromDb;
        _getSearchResults.RunWorkerCompleted += SearchFinished;
        _getSearchResults.RunWorkerAsync(arguments);
    }

RunSearch is exicuted from button_click event.

I have a messagebox inside my SearchFinished method that shows "No Results Found". For some reason, the SearchFinished method is called multiple times sometimes, which causes multiple MessageBoxes to be shown. Is there a workaround for this?

+2  A: 

Rushed the gun with posting this a bit.

Since I'm wiring up the events on button click, every time I click the button, the number of times the event executes goes up. I moved the wire up to the constructor, and my problem was fixed.

Greg R
been bitten by this [figurative] bug many times myself. cases like these, it helps to have some logging - for instance you may have noticed a direct relation between number of executions and button clicks a little sooner ;)
johnny g