Repository: microsoft/PowerToys
File: src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs (C#)

Code before:
                        bool hideWindow = true;

                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            hideWindow = result.Action(new ActionContext
                            {
                                SpecialKeyState = KeyboardHelper.CheckModifiers(),
                            });
                        });

                        if (hideWindow)
                        {
                            Hide();
                        }

                        // Check information file for version mismatch
                        try
                        {
                            // UserSelectedRecord
                            var userSelectedRecordItemData = new UserSelectedRecord.UserSelectedRecordItem();
                            var userSelectedRecordItemStorage = new WoxJsonStorage<UserSelectedRecord.UserSelectedRecordItem>(_userSelectedRecordStorage.GetFileName());
                            userSelectedRecordItemStorage.Load();

                            if (userSelectedRecordItemData != null)
                            {
                                if (userSelectedRecordItemStorage.CheckVersionMismatch(userSelectedRecordItemData, _userSelectedRecordStorage.GetVersionMismatch()))
                                {
                                    if (!userSelectedRecordItemStorage.CheckWithInformationFileToClear(userSelectedRecordItemData))
                                    {
                                        userSelectedRecordItemStorage.Clear();
                                        userSelectedRecordItemStorage.SaveInformationFile(userSelectedRecordItemData);
                                    }
                                }
                            }

                            // History
                            var historyItemData = new HistoryItem();
                            var historyItemStorage = new WoxJsonStorage<HistoryItem>(_historyItemsStorage.GetFileName());
                            historyItemStorage.Load();

                            if (historyItemData != null)
                            {
                                if (historyItemStorage.CheckVersionMismatch(historyItemData, _historyItemsStorage.GetVersionMismatch()))
                                {
                                    if (!historyItemStorage.CheckWithInformationFileToClear(historyItemData))
                                    {
                                        historyItemStorage.Clear();
                                        historyItemStorage.SaveInformationFile(historyItemData);
                                    }
                                }
                            }

Review comment (performance):
Can there be a situation where userSelectedRecordItemStorage._storageHelper.ClearCache has different value than _userSelectedRecordStorage._storageHelper.ClearCache. I believe not? In that case why creating a copy of the storage, can we just use the field member storage?

Code after:
                        bool hideWindow = true;

                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            hideWindow = result.Action(new ActionContext
                            {
                                SpecialKeyState = KeyboardHelper.CheckModifiers(),
                            });
                        });

                        if (hideWindow)
                        {
                            Hide();
                        }

                        if (SelectedIsFromQueryResults())
                        {
                            _userSelectedRecord.Add(result);
                            _history.Add(result.OriginQuery.RawQuery);
                        }
                        else
                        {
                            SelectedResults = Results;
                        }
                    }
                }
            }
        }

        private void InitializeKeyCommands()
        {
            IgnoreCommand = new RelayCommand(_ => { });

            EscCommand = new RelayCommand(_ =>
            {
                if (!SelectedIsFromQueryResults())
                {
                    SelectedResults = Results;
                }
                else
                {
                    Hide();
                }
            });

            SelectNextItemCommand = new RelayCommand(_ =>
            {
                SelectedResults.SelectNextResult();
            });

            SelectPrevItemCommand = new RelayCommand(_ =>