Ejemplo n.º 1
0
 public RoundRobinManager(StaTaskScheduler staScheduler)
 {
     // Create the task (it just runs forever until dispose is called)
     _task = Task.Factory.StartNew(() =>
     {
         Run(_addRemoveQueue, _waitHandle, _cancel.Token);
     }, _cancel.Token, TaskCreationOptions.LongRunning, staScheduler);
 }
Ejemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_tasks != null)
                {
                    for (int cntr = 0; cntr < _tasks.Length; cntr++)
                    {
                        _tasks[cntr].Dispose();
                    }

                    _tasks = null;
                }

                if (_staScheduler != null)
                {
                    _staScheduler.Dispose();
                    _staScheduler = null;
                }
            }
        }
Ejemplo n.º 3
0
        public CameraPool(int numThreads, Color background)
        {
            _staScheduler = new StaTaskScheduler(numThreads);

            _tasks = new TaskWrapper[numThreads];
            for (int cntr = 0; cntr < numThreads; cntr++)
            {
                _tasks[cntr] = new TaskWrapper(_staScheduler, background);
            }
        }
Ejemplo n.º 4
0
 public TaskWrapper(StaTaskScheduler staScheduler, Color background)
 {
     // Create the task (it just runs forever until dispose is called)
     _task = Task.Factory.StartNew(() =>
     {
         Run(this, _cancel.Token, background);
     }, _cancel.Token, TaskCreationOptions.LongRunning, staScheduler);
 }
        private void btnThreads2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Build model in main thread

                Color color = Colors.DodgerBlue;

                // Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color)));
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d));

                // Geometry Model
                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material = materials;
                geometry.BackMaterial = materials;
                geometry.Geometry = UtilityWPF.GetCone_AlongX(3, 1d, 3d);

                geometry.Transform = new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation()));


                Model3DGroup models = new Model3DGroup();
                models.Children.Add(geometry);


                #endregion

                #region Serialize it

                byte[] geometryBytes = null;

                using (MemoryStream stream = new MemoryStream())
                {
                    //XamlServices.Save(stream, geometry);
                    XamlServices.Save(stream, models);
                    stream.Position = 0;

                    geometryBytes = stream.ToArray();
                }

                #endregion

                //  Viewport3D must be created in an STA thread
                if (_staScheduler == null)
                {
                    _staScheduler = new StaTaskScheduler(3);
                }

                Task.Factory.StartNew(() =>
                {
                    ThreadTest2(geometryBytes);
                }, CancellationToken.None, TaskCreationOptions.None, _staScheduler);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Window_Closed(object sender, EventArgs e)
        {
            try
            {
                if (_cameraPool != null)
                {
                    _cameraPool.Dispose();
                    _cameraPool = null;
                }

                if (_staScheduler != null)
                {
                    _staScheduler.Dispose();
                    _staScheduler = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }