コード例 #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
ファイル: VisualTarget.cs プロジェクト: sjyanxin/WPFSource
        //---------------------------------------------------------------------
        //
        //  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();
        }
コード例 #7
0
        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;
        }
コード例 #8
0
        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
ファイル: VisualTarget.cs プロジェクト: alesliehughes/olive
		public VisualTarget (HostVisual hostVisual)
		{
		}
コード例 #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="hostVisual">host visual</param>
 public VisualTargetPresentationSource(HostVisual hostVisual)
 {
     _visualTarget = new VisualTarget(hostVisual);
     AddSource();
 }
コード例 #12
0
        /// <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)
 {
 }
コード例 #14
0
 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(); }));
            }));
        }