Пример #1
0
        /// <summary>
        ///     Runs event loop on current thread
        /// </summary>
        /// <param name="init">First event to be invoked</param>
        /// <param name="state">Event parameter</param>
        public static void Run(SendOrPostCallback init, object state)
        {
            using (var loop = new EventLoopImplementation())
            {
                var oldContext = SynchronizationContext.Current;
                var loopContext = new EventLoopSynchronizationContext(loop);
                try
                {
                    // Install loop context
                    SynchronizationContext.SetSynchronizationContext(loopContext);

                    // Run loop
                    loop.Run(init, state);
                }
                finally
                {
                    // Restore sync context
                    SynchronizationContext.SetSynchronizationContext(oldContext);
                }
            }
        }
 public EventLoopSynchronizationContext(EventLoopImplementation eventLoopImplementation)
 {
     EventLoopImplementation = eventLoopImplementation;
 }