Esempio n. 1
0
        private static void TstMainThreadSyncThread()
        {
            _logger.Log("Begin");

            var invokingInMainThread = new InvokerInMainThread();

            var task = Task.Run(() => {
                while (true)
                {
                    invokingInMainThread.Update();

                    Thread.Sleep(1000);
                }
            });

            Thread.Sleep(5000);

            var invocableInMainThreadObj = new InvocableInMainThread(() => { _logger.Log("^)"); }, invokingInMainThread);

            invocableInMainThreadObj.Run();

            Thread.Sleep(5000);

            _logger.Log("End");
        }
        private Task CreateTaskForMainThread(CancellationToken cancellationToken, IEndpointInfo endpointInfo, object[] paramsList, PlatformProcessInfo processInfo)
        {
            var platformListener = endpointInfo.Object;

            var task = new Task(() =>
            {
                try
                {
                    var invocableInMainThreadObj = new InvocableInMainThread(() => {
                        endpointInfo.MethodInfo.Invoke(platformListener, paramsList);
                    }, _invokingInMainThread);

                    invocableInMainThreadObj.Run();

                    processInfo.Status = ProcessStatus.Completed;
                }
                catch (TargetInvocationException)
                {
                }
                catch (Exception e)
                {
#if DEBUG
                    Log($"e = {e}");
#endif

                    processInfo.Status = ProcessStatus.Faulted;
                }
            }, cancellationToken);

            return(task);
        }
Esempio n. 3
0
        public void RunInMainThread(Action function)
        {
            var invocableInMainThreadObj = new InvocableInMainThread(function, InvokerInMainThread);

            invocableInMainThreadObj.Run();
        }