当前位置: 首页>>代码示例>>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;未经允许,请勿转载。