Exemple #1
0
        public Task PostAsync(Action action)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (EcoreMainloop.IsMainThread)
            {
                try
                {
                    action?.Invoke();
                    tcs.SetResult(true);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }
            else
            {
                EcoreMainloop.PostAndWakeUp(() =>
                {
                    try
                    {
                        action?.Invoke();
                        tcs.SetResult(true);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                });
            }

            return(tcs.Task);
        }
Exemple #2
0
        public async Task PostAsync(Func <Task> action)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (EcoreMainloop.IsMainThread)
            {
                try
                {
                    await action?.Invoke();

                    tcs.SetResult(true);
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }
            else
            {
                EcoreMainloop.PostAndWakeUp(async() =>
                {
                    try
                    {
                        await action?.Invoke();
                        tcs.SetResult(true);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                });
            }

            await tcs.Task;
        }
Exemple #3
0
        public TizenHost(Func <WinUI.Application> appBuilder, string[] args = null)
        {
            Elementary.Initialize();
            Elementary.ThemeOverlay();

            _current = this;

            _appBuilder = appBuilder;
            _args       = args;


            _args ??= Environment
            .GetCommandLineArgs()
            .Skip(1)
            .ToArray();

            bool EnqueueNative(DispatcherQueuePriority priority, DispatcherQueueHandler callback)
            {
                EcoreMainloop.PostAndWakeUp(() => callback());

                return(true);
            }

            Windows.System.DispatcherQueue.EnqueueNativeOverride = EnqueueNative;

            Windows.UI.Core.CoreDispatcher.DispatchOverride        = (d) => EcoreMainloop.PostAndWakeUp(d);
            Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = () => EcoreMainloop.IsMainThread;

            _tizenApplication = new TizenApplication(this);
            _tizenApplication.Run(_args);
        }
Exemple #4
0
 static void PlatformBeginInvokeOnMainThread(Action action)
 {
     if (PlatformIsMainThread)
     {
         action();
     }
     else
     {
         EcoreMainloop.PostAndWakeUp(action);
     }
 }
        public IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action)
        {
            var innerDisp = new SingleAssignmentDisposable();

            EcoreMainloop.PostAndWakeUp(() => {
                if (!innerDisp.IsDisposed)
                {
                    innerDisp.Disposable = action(this, state);
                }
            });
            return(innerDisp);
        }
Exemple #6
0
        public static async void PostAndWakeUp(Action action)
        {
            await _mutex.WaitAsync().ConfigureAwait(false);

            try
            {
                EcoreMainloop.PostAndWakeUp(action);
            }
            finally
            {
                _mutex.Release();
            }
        }
Exemple #7
0
        public TizenHost(Func <WinUI.Application> appBuilder, string[]?args = null)
        {
            Elementary.Initialize();
            Elementary.ThemeOverlay();

            _current = this;

            _appBuilder = appBuilder;

            Windows.UI.Core.CoreDispatcher.DispatchOverride        = (d) => EcoreMainloop.PostAndWakeUp(d);
            Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = () => EcoreMainloop.IsMainThread;

            _tizenApplication = new TizenApplication(this);
            _tizenApplication.Run(args);
        }
Exemple #8
0
        public TizenHost(Func <WinUI.Application> appBuilder)
        {
            Elementary.Initialize();
            Elementary.ThemeOverlay();

            _current = this;

            _appBuilder = appBuilder;

            Windows.UI.Core.CoreDispatcher.DispatchOverride        = (d) => EcoreMainloop.PostAndWakeUp(d);
            Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = () => EcoreMainloop.IsMainThread;

            _tizenApplication = new TizenApplication(this);
            _tizenApplication.Run(Environment.GetCommandLineArgs());
        }
Exemple #9
0
        /// <summary>
        /// Creates a WpfHost element to host a Uno-Skia into a WPF application.
        /// </summary>
        /// <remarks>
        /// If args are omitted, those from Environment.GetCommandLineArgs() will be used.
        /// </remarks>
        public TizenHost(Func <WinUI.Application> appBuilder, string[] args = null)
        {
            Elementary.Initialize();
            Elementary.ThemeOverlay();

            _current = this;

            _appBuilder = appBuilder;
            _args       = args;


            _args ??= Environment
            .GetCommandLineArgs()
            .Skip(1)
            .ToArray();

            Windows.UI.Core.CoreDispatcher.DispatchOverride
                = (d) => EcoreMainloop.PostAndWakeUp(d);

            _tizenApplication = new TizenApplication(this);
            _tizenApplication.Run(_args);
        }