예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaElementThreadInfo"/> class.
        /// </summary>
        /// <param name="hostVisual">The host visual.</param>
        /// <param name="thread">The thread.</param>
        public MediaElementThreadInfo(HostVisual hostVisual, Thread thread)
        {
            Argument.IsNotNull("hostVisual", hostVisual);
            Argument.IsNotNull("thread", thread);

            HostVisual = hostVisual;
            Thread = thread;
        }
예제 #2
0
        //---------------------------------------------------------------------
        //
        //  Constructors
        // 
        //---------------------------------------------------------------------
 
        #region Constructors 

        /// <summary> 
        /// VisualTarget
        /// </summary>
        public VisualTarget(HostVisual hostVisual)
        { 
            if (hostVisual == null)
            { 
                throw new ArgumentNullException("hostVisual"); 
            }
 
            _hostVisual = hostVisual;
            _connected = false;
            MediaContext.RegisterICompositionTarget(Dispatcher, this);
        } 
예제 #3
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="createContent">create content delegate</param>
            /// <param name="invalidateMeasure">action to invalidate the measure</param>
            public ThreadedVisualHelper(CreateContentDelegate createContent, Action invalidateMeasure)
            {
                _hostVisual = new HostVisual();
                _createContent = createContent;
                _invalidateMeasure = invalidateMeasure;

                Thread backgroundUi = new Thread(CreateAndShowContent);
                backgroundUi.SetApartmentState(ApartmentState.STA);
                backgroundUi.IsBackground = true;
                backgroundUi.Start();

                _resetEvent.WaitOne();
            }
예제 #4
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            var hostVisual = new HostVisual();
            Thread thread = new Thread(MediaWorkerThread);
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start(hostVisual);

            _threadReadyEvent.WaitOne();
            this.Child = hostVisual;
        }
예제 #5
0
        /// <summary>
        /// Creates the media element on worker thread.
        /// <para />
        /// Note that the <see cref="MediaElementThreadInfo"/> implements <see cref="IDisposable"/>.
        /// </summary>
        /// <returns>The media element thread info.</returns>
        public static MediaElementThreadInfo CreateMediaElementsOnWorkerThread(Func<Visual> createVisual)
        {
            Argument.IsNotNull("createVisual", createVisual);

            var visual = new HostVisual();

            var thread = new Thread(WorkerThread);

            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start(new object[] { visual, createVisual });

            _autoResetEvent.WaitOne();

            return new MediaElementThreadInfo(visual, thread);
        }
예제 #6
0
        public ThreadedVisualHelper(
            CreateContentFunction createContent,
            Action invalidateMeasure)
        {
            _hostVisual = new HostVisual();
            _createContent = createContent;
            _invalidateMeasure = invalidateMeasure;

            Thread backgroundUi = new Thread(CreateAndShowContent);
            backgroundUi.SetApartmentState(ApartmentState.STA);
            backgroundUi.Name = "BackgroundVisualHostThread";
            backgroundUi.IsBackground = true;
            backgroundUi.Start();

            _sync.WaitOne();
        }
        public Visual CreateThreadedLabelTimer()
        {
            // Create the HostVisual that will "contain" the VisualTarget
            // on the worker thread.
            var aHostVisual = new HostVisual();

            // Spin up a worker thread, and pass it the HostVisual that it
            // should be part of.
            var aThread = new Thread(RecordTimerWorkerThread);
            aThread.SetApartmentState(ApartmentState.STA);

            aThread.IsBackground = true;
            aThread.Start(aHostVisual);

            // Wait for the worker thread to spin up and create the VisualTarget.
            myChildVisualTargetEvent.WaitOne();

            return aHostVisual;
        }
        protected virtual void LoadThreadSeparatedControl()
        {
            if (SeparateThreadDispatcher != null) return;

            AutoResetEvent sync = new AutoResetEvent(false);
            HostVisual = new HostVisual();

            AddLogicalChild(HostVisual);
            AddVisualChild(HostVisual);
            
            if (DesignerProperties.GetIsInDesignMode(this))
                return;

            var thread = new Thread(() =>
            {
                TargetElement = CreateThreadSeparatedControl();

                if (TargetElement == null) return;

                VisualTarget = new VisualTargetPresentationSource(HostVisual);
                VisualTarget.RootVisual = TargetElement;

                Dispatcher.BeginInvoke(new Action(() => { InvalidateMeasure(); }));

                sync.Set();

                Dispatcher.Run();

                VisualTarget.Dispose();
            })
            {
                IsBackground = true
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            sync.WaitOne();
        }
예제 #9
0
 private void CreateContentHelper()
 {
     _threadedHelper = new ThreadedVisualHelper(CreateContent, SafeInvalidateMeasure);
     _hostVisual = _threadedHelper.HostVisual;
 }
예제 #10
0
		public VisualTarget (HostVisual hostVisual)
		{
		}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="hostVisual">host visual</param>
 public VisualTargetPresentationSource(HostVisual hostVisual)
 {
     _visualTarget = new VisualTarget(hostVisual);
     AddSource();
 }
        /// <summary>
        /// Creates the media element on worker thread.
        /// </summary>
        /// <returns></returns>
        private HostVisual CreateMediaElementOnWorkerThread()
        {
            var hostVisual = new HostVisual();

            _thread = new Thread(MediaWorkerThread);
            _thread.SetApartmentState(ApartmentState.STA);
            _thread.IsBackground = true;
            _thread.Start(hostVisual);

            _autoResetEvent.WaitOne();

            return hostVisual;
        }
예제 #13
0
 public VisualTarget(HostVisual hostVisual)
 {
 }
 public VisualTargetPresentationSource(HostVisual theHostVisual)
 {
     myVisualTarget = new VisualTarget(theHostVisual);
 }
예제 #15
0
        protected override void LoadThreadSeparatedControl()
        {
            HostVisual = new HostVisual();

            AddLogicalChild(HostVisual);
            AddVisualChild(HostVisual);

            if (DesignerProperties.GetIsInDesignMode(this))
                return;

            CommonDispatcher.BeginInvoke(new Action(() =>
            {
                   TargetElement = CreateThreadSeparatedControl();

                if (TargetElement == null) return;

                VisualTarget = new VisualTargetPresentationSource(HostVisual);
                VisualTarget.RootVisual = TargetElement;

                Dispatcher.BeginInvoke(new Action(() => { InvalidateMeasure(); }));
            }));
        }