コード例 #1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_mediaElementThreadInfo != null)
            {
                return;
            }

            _mediaElementThreadInfo = MediaElementThreadFactory.CreateMediaElementsOnWorkerThread(CreateBusyIndicator);
            Child = _mediaElementThreadInfo.HostVisual;
        }
コード例 #2
0
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            if (_ignoreUnloadedEventCounter > 0)
            {
                _ignoreUnloadedEventCounter--;
                return;
            }

            if (_mediaElementThreadInfo != null)
            {
                _mediaElementThreadInfo.Dispose();
                _mediaElementThreadInfo = null;
            }
        }
コード例 #3
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 thread = new Thread(WorkerThread);

            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;

            var mediaElementThreadInfo = new MediaElementThreadInfo(new HostVisual(), createVisual, thread);

            thread.Start(mediaElementThreadInfo);

            // Wait for the element to be created by the thread
            AutoResetEvent.WaitOne();

            return(mediaElementThreadInfo);
        }