<commit_before>using MvvmScarletToolkit.Observables;
using System;
using System.Collections.Specialized;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace MvvmScarletToolkit.Wpf
{
    public sealed class ToastService : ViewModelListBase<IToast>, IToastService
    {
        private static readonly Lazy<ToastService> _default = new Lazy<ToastService>(() => new ToastService(ScarletCommandBuilder.Default, new ToastServiceConfiguration()));

        public static IToastService Default => _default.Value;

        private Window? _host;
        private DispatcherTimer? _closingTimer;

        public string WindowStyleKey { get; }
        public int WindowOffset { get; }
        public TimeSpan WindowCloseDelay { get; }
        public TimeSpan ToastCloseDelay { get; }
        public Rect? Origin { get; set; }

        public ToastService(IScarletCommandBuilder commandBuilder, ToastServiceConfiguration configuration)
            : base(commandBuilder)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (configuration.WindowStyleKey is null)
            {
                throw new ArgumentNullException(nameof(configuration.WindowStyleKey));
            }

            WindowStyleKey = configuration.WindowStyleKey;
            WindowOffset = configuration.WindowOffset;

            WindowCloseDelay = configuration.WindowCloseDelay;
            ToastCloseDelay = configuration.ToastCloseDelay;
        }

        public async Task Show(IToast toast)
        {
            if (_host is null)
            {
                _host = new Window()
                {
                    DataContext = this,
                };

                var obj = Application.Current.FindResource(WindowStyleKey);
                if (obj is Style style && style.TargetType == typeof(Window))
                {
                    _host.Style = style;
                }

                _host.Closing += OnHostClosing;
                _host.Loaded += OnLoaded;
                _host.Show();
            }

            Reposition(_host, Origin, WindowOffset);

            if (!_host.IsVisible)
            {
                _host.Visibility = Visibility.Visible;
            }

            await Add(toast).ConfigureAwait(false);
<commit_msg>initialize toast dependcies via dispatcher<commit_after>using MvvmScarletToolkit.Observables;
using System;
using System.Collections.Specialized;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace MvvmScarletToolkit.Wpf
{
    public sealed class ToastService : ViewModelListBase<IToast>, IToastService
    {
        private static readonly Lazy<ToastService> _default = new Lazy<ToastService>(() => new ToastService(ScarletCommandBuilder.Default, new ToastServiceConfiguration()));

        public static IToastService Default => _default.Value;

        private Window? _host;
        private DispatcherTimer? _closingTimer;

        public string WindowStyleKey { get; }
        public int WindowOffset { get; }
        public TimeSpan WindowCloseDelay { get; }
        public TimeSpan ToastCloseDelay { get; }
        public Rect? Origin { get; set; }

        public ToastService(IScarletCommandBuilder commandBuilder, ToastServiceConfiguration configuration)
            : base(commandBuilder)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (configuration.WindowStyleKey is null)
            {
                throw new ArgumentNullException(nameof(configuration.WindowStyleKey));
            }

            WindowStyleKey = configuration.WindowStyleKey;
            WindowOffset = configuration.WindowOffset;

            WindowCloseDelay = configuration.WindowCloseDelay;
            ToastCloseDelay = configuration.ToastCloseDelay;
        }

        public async Task Show(IToast toast)
        {
            await Dispatcher.Invoke(() =>
            {
                if (_host is null)
                {
                    _host = new Window()
                    {
                        DataContext = this,
                    };

                    var obj = Application.Current.FindResource(WindowStyleKey);
                    if (obj is Style style && style.TargetType == typeof(Window))
                    {
                        _host.Style = style;
                    }

                    _host.Closing += OnHostClosing;
                    _host.Loaded += OnLoaded;
                    _host.Show();
                }

                Reposition(_host, Origin, WindowOffset);

                if (!_host.IsVisible)
                {
                    _host.Visibility = Visibility.Visible;
                }
            }).ConfigureAwait(false);

            await Add(toast).ConfigureAwait(false);

{'fraction_non_alphanumeric': 0.0728476821192053, 'fraction_numerical': 0.0, 'mean_word_length': 1.8382687927107062, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5629799', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1149, 'n_words': 269}