当前位置: 首页>>代码示例>>C#>>正文


C# Barrier.Dispose方法代码示例

本文整理汇总了C#中System.Threading.Barrier.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Barrier.Dispose方法的具体用法?C# Barrier.Dispose怎么用?C# Barrier.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Barrier的用法示例。


在下文中一共展示了Barrier.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DownloadAllTreatmentImages

        /// <summary>
        /// Download all the images for the current session
        /// </summary>
        public void DownloadAllTreatmentImages()
        {
            Barrier barrier = new Barrier(_patient.PatientTreatment.TrainingList.Count + 2);

            Task treatmentThread = new Task(() =>
            {
                //Downloading all thumbs in treatment
                DownloadTreatment();

                barrier.SignalAndWait();
            });
            treatmentThread.Start();

            foreach(Training t in _patient.PatientTreatment.TrainingList)
            {
                Task tt = new Task(() =>
                {
                    DownloadTraining(_patient.PatientTreatment.TrainingList.IndexOf(t));
                    barrier.SignalAndWait();
                });
                tt.Start();

            }

            barrier.SignalAndWait();
            barrier.Dispose();
        }
开发者ID:amirben,项目名称:VideoTherapy,代码行数:30,代码来源:DownloadCache.cs

示例2: ExecuteTasksSequentiallyAndInOrder

		public async Task ExecuteTasksSequentiallyAndInOrder()
		{
			using (var testSubject = new MissionControl())
			{
				var fool = testSubject.SpawnFool();
				var sentMessage = new SimpleTestMessage();
				SimpleTestMessage receivedMessage = null;
				var barrier = new Barrier(2);
				var first = fool.DoWork(
					sentMessage,
					msg =>
					{
						barrier.SignalAndWait();
						receivedMessage = msg;
					});
				var second = fool.DoWork(sentMessage, msg => { barrier.SignalAndWait(); });
				var done = Task.WhenAll(first, second)
					.ContinueWith(
						t =>
						{
							barrier.Dispose();
							return Work.Completed;
						});
				var timeout = Task.Delay(100.Milliseconds())
					.ContinueWith(t => Work.TimedOut);
				var result = await await Task.WhenAny(done, timeout);
				result.Should()
					.Be(Work.TimedOut);
			}
		}
开发者ID:arlobelshee,项目名称:Fools.net,代码行数:30,代码来源:FoolExecutionAndMessaging.cs

示例3: Start

 public void Start()
 {
     _barrier = new Barrier(2);
     _worker = new Thread(Worker);
     _worker.Start();
     _barrier.SignalAndWait();
     _barrier.Dispose();
     _barrier = null;
 }
开发者ID:janderit,项目名称:rocNet0,代码行数:9,代码来源:ZeroMqResourceProviderFacade.cs

示例4: CancelBeforeWait

        public static bool CancelBeforeWait()
        {
            TestHarness.TestLog("* BarrierCancellationTests.CancelBeforeWait()");
            bool passed = true;

            Barrier barrier = new Barrier(3);
            
            CancellationTokenSource cs = new CancellationTokenSource();
            cs.Cancel();
            CancellationToken ct = cs.Token;
            
            const int millisec = 100;
            TimeSpan timeSpan = new TimeSpan(100);
            
            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => barrier.SignalAndWait(ct), ct, "An OCE should have been thrown.");
            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => barrier.SignalAndWait(millisec, ct), ct, "An OCE should have been thrown.");
            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => barrier.SignalAndWait(timeSpan, ct), ct, "An OCE should have been thrown.");

            barrier.Dispose();
            return passed;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:21,代码来源:BarrierCancellationTests.cs

示例5: BarrierCancellationTestsCancelBeforeWait

        public static void BarrierCancellationTestsCancelBeforeWait()
        {
            Barrier barrier = new Barrier(3);

            CancellationTokenSource cs = new CancellationTokenSource();
            cs.Cancel();
            CancellationToken ct = cs.Token;

            const int millisec = 100;
            TimeSpan timeSpan = new TimeSpan(100);

            EnsureOperationCanceledExceptionThrown(
               () => barrier.SignalAndWait(ct), ct,
               "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(
               () => barrier.SignalAndWait(millisec, ct), ct,
               "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(
               () => barrier.SignalAndWait(timeSpan, ct), ct,
               "CancelBeforeWait:  An OCE should have been thrown.");

            barrier.Dispose();
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:23,代码来源:BarrierCancellationTests.cs

示例6: BtnAll_Click

        private void BtnAll_Click(object sender, EventArgs e)
        {
            EnableUI(false);
            _sorterRunning = int.MaxValue;

            bool fast = ModifierKeys == Keys.Shift;

            _cts = new CancellationTokenSource();
            var barrier = new Barrier(0, DrawArrays);
            var tasks = new List<Task>(_sorters.Count)
            {
                // Dummy task, so that the continuation below is run for sure.
                Task.Run(() => { return; }),
            };

            var ui = SynchronizationContext.Current;
            for (int i = 0; i < _sorters.Count; ++i)
            {
                var sorter = _sorters[i];
                if (sorter.Run)
                {
                    sorter.Abort = _cts.Token;
                    if (!fast)
                    {
                        sorter.SteppedExecution = barrier;
                        sorter.SteppedExecution.AddParticipant();
                    }
                    sorter.Numbers = _numbers;
                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        sorter.Sort();
                    }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current));
                }
            }

            Task.WhenAll(tasks).ContinueWith(_ =>
            {
                ui.Post(delegate
                {
                    EnableUI(true);
                    DrawArrays(null);
                    DgvSorters.Refresh();
                }, null);
                barrier.Dispose();
                _cts.Dispose();
                _cts = null;
            });
        }
开发者ID:T-Becker,项目名称:SortVis,代码行数:48,代码来源:FrmMain.cs

示例7: DownloadTreatment

        /// <summary>
        /// Download training preview images for the treatment screen
        /// </summary>
        public void DownloadTreatment()
        {
            //crearte dir for user (if not already created)
            //string newDir = CreateDir(dir, _patient.AccountId.ToString());
            //newDir = CreateDir(newDir, _patient.PatientTreatment.TreatmentNumber.ToString());
            string newDir = CreateDir(dir, "treatmentThumb");

            //initilaize the barrier
            int size = _patient.PatientTreatment.TrainingList.Count;
            //Barrier _barrier = new Barrier(size + 1);
            Barrier _barrier = new Barrier(1);

            for (int i = 0; i < size; i++)
            {
                int temp = i;

                string _from = _patient.PatientTreatment.TrainingList[temp].TrainingThumbs;
                string _to = newDir + "\\" + _patient.PatientTreatment.TrainingList[temp].TrainingId + ".png";
                _patient.PatientTreatment.TrainingList[temp].TrainingThumbs = _to;

                if (!File.Exists(_to))
                {
                    _barrier.AddParticipant();
                    Task tempThread = new Task(() =>
                    {
                        DownloadFile(_from, _to);
                        _barrier.SignalAndWait();
                    });
                    tempThread.Start();
                }

            }

            _barrier.SignalAndWait();

            _barrier.Dispose();
        }
开发者ID:amirben,项目名称:VideoTherapy,代码行数:40,代码来源:DownloadCache.cs

示例8: TerminateWorker

 private void TerminateWorker()
 {
     _barrier = new Barrier(2);
     _terminate = true;
     _barrier.SignalAndWait();
     _barrier.Dispose();
     _barrier = null;
 }
开发者ID:janderit,项目名称:rocNet0,代码行数:8,代码来源:ZeroMqResourceProviderFacade.cs

示例9: RunBarrierTest6_Dispose

 /// <summary>
 /// Test Dispose
 /// </summary>
 /// <returns>Tru if the test succeeded, false otherwise</returns>
 private static bool RunBarrierTest6_Dispose()
 {
     TestHarness.TestLog("*RunBarrierTest6_Dispose");
     Barrier b = new Barrier(1);
     b.Dispose();
     try
     {
         b.SignalAndWait();
     }
     catch (ObjectDisposedException)
     {
         TestHarness.TestLog("Dispose succeeded");
         return true;
     }
     TestHarness.TestLog("Cancel failed, SignalAndWait didn't throw exceptions after Dispose.");
     return false;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:21,代码来源:BarrierTests.cs

示例10: Dijkstra_p

        /// <summary>
        /// Parallel Dijkstra algorithm
        /// </summary>
        /// 
        /// <param name="graph">
        /// <see cref="Graph"/> object to check the path for
        /// </param>
        /// 
        /// <param name="start">
        /// Start
        /// </param>
        /// 
        /// <returns>
        /// List of <see cref="Link"/> objects
        /// </returns>
        private static List<Link> Dijkstra_p(Graph graph, int start)
        {
            List<Vertex> P =
                (from v in graph.Vertices
                 select new Vertex(v, graph.Links)).ToList();

            var qT =
                from vertex in P
                where vertex.ID != start
                orderby vertex.ID ascending
                select vertex;

            Queue<Vertex> Q = new Queue<Vertex>(qT);

            Vertex curr = P[start];
            curr.closest_distance = 0.0f;

            while (Q.Count > 0)
            {
                Barrier barrier = new Barrier(curr.neighbors.Count + 1);

                foreach (Tuple<int, double> n in curr.neighbors)
                {
                    var tuple = n;
                    ThreadPool.QueueUserWorkItem(
                        obj =>
                        {
                            Vertex neighbor = P[tuple.Item1];
                            double dist = tuple.Item2 + curr.closest_distance;

                            bool contains = (from v in Q where v.ID == tuple.Item1 select v).Count() > 0;

                            if (contains && (dist < neighbor.closest_distance))
                            {
                                neighbor.closest = curr;
                                neighbor.closest_distance = dist;
                            }

                            barrier.SignalAndWait();
                        },
                        null);
                }

                barrier.SignalAndWait();

                barrier.Dispose();

                curr = Q.Dequeue();
            }

            return
                (from v in P
                 where v.ID != start
                 select new Link(v.ID, v.closest.ID, v.closest_distance)).ToList();
        }
开发者ID:ethansudman,项目名称:FinalProject,代码行数:70,代码来源:Program.cs

示例11: NotifyCallQueueOnEveryUserButPostingUser

		public void NotifyCallQueueOnEveryUserButPostingUser()
		{
			var service = GetService();
			var topic = new Topic(123);
			var user = new User(768, DateTime.MinValue);
			var list = new List<User> { user, new User(2, DateTime.MinValue) };
			_mockSubRepo.Setup(s => s.GetSubscribedUsersThatHaveViewed(topic.TopicID)).Returns(list);
			var topicLink = "foo";
			Func<User, string> gen = u => "x" + u.UserID;
			var barrier = new Barrier(1);
			Action action = () =>
			{
				service.NotifySubscribers(topic, user, topicLink, gen);
				barrier.SignalAndWait();
			};
			action.Invoke();
			barrier.Dispose();
			_mockSubTopicEmail.Verify(s => s.ComposeAndQueue(topic, It.IsAny<User>(), topicLink, It.IsAny<string>()), Times.Exactly(1));
			_mockSubTopicEmail.Verify(s => s.ComposeAndQueue(topic, list[0], topicLink, "x" + list[0].UserID), Times.Exactly(0));
			_mockSubTopicEmail.Verify(s => s.ComposeAndQueue(topic, list[1], topicLink, "x" + list[1].UserID), Times.Exactly(1));
		}
开发者ID:andyliyuze,项目名称:POPForums,代码行数:21,代码来源:SubscribedTopicsServiceTests.cs


注:本文中的System.Threading.Barrier.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。