Esempio n. 1
0
        private void BtnSwitchClick(object sender, RoutedEventArgs e)
        {
            if (_isRunning)
            {
                _btnSwitch.Content = "Start Translator";

                _isRunning = false;

                UnlockUiElements();

                _translator.Dispose();
            }
            else
            {
                _btnSwitch.Content = "Stop Translator";

                var selectedLanguageName = ((Language)_comboBoxLanguages.SelectedItem).Name;
                _configurations.AppConfigManager.SaveOrUpdate("ToLanguage", selectedLanguageName);
                _configurations.ApplicationConfiguration.ToLanguage = new Language(selectedLanguageName, LanguageMapping.All[selectedLanguageName]);

                PrepareTranslators();
                LockUiElements();

                this.DispatchingAsync(async() =>
                {
                    if (!_translator.IsInitialized)
                    {
                        await _translator.InitializeAsync();
                    }
                });

                _isRunning = true;
            }
        }
Esempio n. 2
0
        private void btnSwitch_Click(object sender, RoutedEventArgs e)
        {
            if (isRunning)
            {
                BtnSwitch.Content = "Start Translator";

                isRunning = false;

                UnlockUiElements();

                translator.Dispose();
            }
            else
            {
                BtnSwitch.Content = "Stop Translator";

                configuration.SetAndPersistConfigurationManager(
                    nameof(configuration.ToLanguage),
                    ((Language)ComboBoxLanguages.SelectedItem).Name);

                PrepareTranslators();
                LockUiElements();

                Task.Run(
                    async() =>
                {
                    await Dispatcher.InvokeAsync(
                        async() =>
                    {
                        if (!translator.IsInitialized)
                        {
                            await translator.InitializeAsync();
                        }
                    });
                });

                isRunning = true;
            }
        }