當前位置: 首頁>>代碼示例>>C#>>正文


C# AsyncSubject.Dispose方法代碼示例

本文整理匯總了C#中AsyncSubject.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# AsyncSubject.Dispose方法的具體用法?C# AsyncSubject.Dispose怎麽用?C# AsyncSubject.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AsyncSubject的用法示例。


在下文中一共展示了AsyncSubject.Dispose方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HasObservers_Dispose2

        public void HasObservers_Dispose2()
        {
            var s = new AsyncSubject<int>();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            var d = s.Subscribe(_ => { });
            Assert.IsTrue(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            d.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsTrue(s.IsDisposed);
        }
開發者ID:Ziriax,項目名稱:Rx.NET,代碼行數:18,代碼來源:AsyncSubjectTest.cs

示例2: HasObservers_Dispose3

        public void HasObservers_Dispose3()
        {
            var s = new AsyncSubject<int>();
            Assert.IsFalse(s.HasObservers);
            Assert.IsFalse(s.IsDisposed);

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
            Assert.IsTrue(s.IsDisposed);
        }
開發者ID:Ziriax,項目名稱:Rx.NET,代碼行數:10,代碼來源:AsyncSubjectTest.cs

示例3: AcquireReadOrWriteLockObservable

		/// <summary>
		/// Acquires the read or write lock on the scheduler, as observable.
		/// </summary>
		/// <param name="schedulingTaskFactory">The task factory.</param>
		/// <returns></returns>
		private IObservable<ReaderWriterLock> AcquireReadOrWriteLockObservable(TaskFactory schedulingTaskFactory)
		{
			// check for incorrect entry once we have already been disposed
			if (IsDisposed)
				return Observable.Throw<ReaderWriterLock>(new ObjectDisposedException(this.GetType().Name));

			// basically what happens here is we use the (concurrent) reader or (exclusive) handed in
			// and schedule a new tpl task on it which merely wraps or contains chained IDisposable creation.
			// What happens then is, we return a 'future' promise or timeslot for whenever the ConcurrentExclusiveSchedulerPair
			// does actually start working on that TPL task (meaning that by its own, internal r/w locking, the task was up next).

			// this is the result we hand back to the caller
			var asyncSubject = new AsyncSubject<ReaderWriterLock>();
			var gate = new AsyncSubject<Unit>();

			schedulingTaskFactory.StartNew(async () =>
			{
				// this asyncSubject is the one actually handed back to the method's caller as IDisposable instance
				// & whenever that one is disposed, the gate gets unblocked \o/
				asyncSubject.OnNext(
					new ReaderWriterLock(
						Interlocked.Increment(ref _scheduledOperationId),
						schedulingTaskFactory == ExclusiveTaskFactory,
						Disposable.Create(() =>
						{
							gate.OnNext(Unit.Default);
							gate.OnCompleted();
						})));
				asyncSubject.OnCompleted();

				// once the asyncSubject's ticket has been disposed, this gate gets unlocked, too
				await gate;

                // cleanup
                gate.Dispose();
			    gate = null;
			});

			return asyncSubject;
		}
開發者ID:jbattermann,項目名稱:JB.Common,代碼行數:45,代碼來源:AsyncReaderWriterLock.cs


注:本文中的AsyncSubject.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。