Exemple #1
0
        public static IExecuteResult ExecuteInBackground(Action action)
        {
            var result = new ExecuteThreadResult();

            ThreadPool.QueueUserWorkItem(state =>
            {
                action();
                lock (_queueSync)
                {
                    _queue.Enqueue(result.Resolve);
                }
            });

            return(result);
        }
Exemple #2
0
        public static IExecuteResult <T> ExecuteInBackground <T>(Func <T> action)
        {
            var result = new ExecuteThreadResult <T>();

            ThreadPool.QueueUserWorkItem(state =>
            {
                var actionResult = action();
                lock (_queueSync)
                {
                    _queue.Enqueue(() =>
                    {
                        result.Resolve(actionResult);
                    });
                }
            });

            return(result);
        }