예제 #1
0
        private async void CharacterSheetViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            CancellationTokenSource objTempTokenSource = Interlocked.Exchange(ref _objRefresherCancellationTokenSource, null);

            if (objTempTokenSource?.IsCancellationRequested == false)
            {
                objTempTokenSource.Cancel(false);
                objTempTokenSource.Dispose();
            }

            objTempTokenSource = Interlocked.Exchange(ref _objOutputGeneratorCancellationTokenSource, null);
            if (objTempTokenSource?.IsCancellationRequested == false)
            {
                objTempTokenSource.Cancel(false);
                objTempTokenSource.Dispose();
            }

            foreach (Character objCharacter in _lstCharacters)
            {
                objCharacter.PropertyChanged         -= ObjCharacterOnPropertyChanged;
                objCharacter.SettingsPropertyChanged -= ObjCharacterOnSettingsPropertyChanged;
            }

            // Remove the mugshots directory when the form closes.
            try
            {
                await Utils.SafeDeleteDirectoryAsync(Path.Combine(Utils.GetStartupPath, "mugshots"), token : _objGenericToken);
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }

            try
            {
                await _tskRefresher;
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
            try
            {
                await _tskOutputGenerator;
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
            _objGenericFormClosingCancellationTokenSource?.Cancel(false);
        }
예제 #2
0
        private async void CharacterSheetViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            _objRefresherCancellationTokenSource?.Cancel(false);
            _objOutputGeneratorCancellationTokenSource?.Cancel(false);

            // Remove the mugshots directory when the form closes.
            await Utils.SafeDeleteDirectoryAsync(Path.Combine(Utils.GetStartupPath, "mugshots"));

            // Clear the reference to the character's Print window.
            foreach (CharacterShared objCharacterShared in Program.MainForm.OpenCharacterForms)
            {
                if (objCharacterShared.PrintWindow == this)
                {
                    objCharacterShared.PrintWindow = null;
                }
            }
        }