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


C# CompositeDisposable类代码示例

本文整理汇总了C#中CompositeDisposable的典型用法代码示例。如果您正苦于以下问题:C# CompositeDisposable类的具体用法?C# CompositeDisposable怎么用?C# CompositeDisposable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: HandleClients

        public static IDisposable HandleClients(TcpListener listener, Func<TcpClient, string, Task> handleClientAccessPolicy, string policyResponse)
        {
            listener.Start();

            var disposableHandler = ThreadPoolScheduler.Instance.ScheduleAsync(async (scheduler, ct) =>
            {
                var disposable = new BooleanDisposable();

                while (!disposable.IsDisposed)
                {
                    var client = await listener.AcceptTcpClientAsync();
                    await handleClientAccessPolicy(client, policyResponse);
                    await scheduler.Yield();
                }

                return disposable;
            });

            var compositeDisposable = new CompositeDisposable();

            compositeDisposable.Add(Disposable.Create(() => listener.Stop()));
            compositeDisposable.Add(disposableHandler);

            return compositeDisposable;
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:25,代码来源:PolicyHandler.cs

示例2: Receive

        public IObservable<string> Receive(byte[] buffer, IScheduler scheduler)
        {
            return Observable.Create<string>(observer =>
                {
                    var disposable = new CompositeDisposable();
                    this.connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
                    var subject = new Subject<Unit>();

                    var disposableEventSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
                    {
                        if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                        {
                            subject.OnNext(Unit.Default);
                        }
                    });

                    var disposableActions = subject.ObserveOn(scheduler).Subscribe(_ =>
                    {
                        if (!connectionToken.Socket.ReceiveAsync(connectionToken.SocketEvent))
                        {
                            if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                            {
                                subject.OnNext(Unit.Default);
                            }
                        }
                    });

                    subject.OnNext(Unit.Default);

                    disposable.Add(disposableEventSubscription);
                    disposable.Add(disposableActions);

                    return disposable;
                });
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:35,代码来源:RedisReceiver.cs

示例3: Initialize

        internal static void Initialize()
        {
            if (!Setting.IsLoaded || !Setting.IsBehaviorLogEnabled.Value)
            {
                return;
            }

            var disposables = new CompositeDisposable();
            try
            {
                var file = new FileStream(
                    Path.Combine(App.ConfigurationDirectoryPath, App.BehaviorLogFileName),
                    FileMode.Append,
                    FileAccess.Write,
                    FileShare.ReadWrite);
                var writer = new StreamWriter(file) { AutoFlush = true };
                _writer = writer.WriteLine;
                disposables.Add(Disposable.Create(() => _writer = null));
                disposables.Add(writer);
                disposables.Add(file);
            }
            finally
            {
                _disposable = disposables;
            }
        }
开发者ID:upsilon,项目名称:StarryEyes,代码行数:26,代码来源:BehaviorLogger.cs

示例4: PrimeExperiment

    public void PrimeExperiment()
    {
      IObservable<long> xs = Observable.Interval(TimeSpan.FromSeconds(1))
        .Do(ConsoleOutput(Text.Generated))
        .Take(3);

      IObservable<long> pruned = xs.PublishLast().Prime();

      for (int r = 0; r < 2; r++)
      {
        using (var subscriptions = new CompositeDisposable())
        {
          for (int s = 0; s < 5; s++)
          {
            Thread.Sleep(TimeSpan.FromSeconds(.4));

            TraceLine(Text.SubscribingFormat, s);

            subscriptions.Add(
              pruned.Subscribe(ConsoleOutput(Text.NamedObserverFormat, s)));
          }

          Thread.Sleep(TimeSpan.FromSeconds(2));
        }
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:26,代码来源:PrimingLab.cs

示例5: AutoDisposeSampleProvider

 public AutoDisposeSampleProvider(ISampleProvider provider,
      IEnumerable<IDisposable> disposables)
 {
     this._provider = provider;
     this._disposables = new CompositeDisposable(disposables);
     this.WaveFormat = provider.WaveFormat;
 }
开发者ID:Kei-Nanigashi,项目名称:StarryEyes,代码行数:7,代码来源:AutoDisposeFileReader.cs

示例6: ReactiveListener

        /// <summary>
        /// Initializes the listener with the given port.
        /// </summary>
        public ReactiveListener(int port)
        {
            this.port = port;
            tracer.ReactiveListenerCreated(port);

            this.socketDisposable = new CompositeDisposable();
        }
开发者ID:neuecc,项目名称:reactivesockets,代码行数:10,代码来源:ReactiveListener.cs

示例7: PressableController

        public PressableController(FrameworkElement element, PressableModel model, KinectRegion kinectRegion)
        {
            this.element = new WeakReference(element);
            this.kinectRegion = kinectRegion;
            this.inputModel = model;

            if (this.inputModel == null)
                return;

            this.eventSubscriptions = new CompositeDisposable 
            {
                this.inputModel.PressingStartedObservable()
                               .Subscribe(_ => VisualStateManager.GoToState(this.Control, "Focused", true)),

                this.inputModel.HoldingObservable()
                               .Subscribe(_ => Debug.WriteLine(string.Format("Holding: {0}, ", DateTime.Now))),

                this.inputModel.PressingUpdatedObservable()
                               .Subscribe(_ => Debug.WriteLine(string.Format("PressingUpdated: {0}, ", DateTime.Now))),

                this.inputModel.PressingCompletedObservable()
                               .Subscribe(_ => VisualStateManager.GoToState(this.Control, "Unfocused", true)),

                this.inputModel.TappedObservable()
                               .Subscribe(_ => Debug.WriteLine(string.Format("Tapped: {0}, ", DateTime.Now))),
            };
        }
开发者ID:teckyravi,项目名称:Kinect.ReactiveV2,代码行数:27,代码来源:PressableController.cs

示例8: Clear

 public void Clear()
 {
     var d = new CompositeDisposable (Disposable.Empty);
     Assert.AreEqual (1, d.Count, "#1");
     d.Clear ();
     Assert.AreEqual (0, d.Count, "#2");
 }
开发者ID:jorik041,项目名称:mono-reactive,代码行数:7,代码来源:CompositeDisposableTest.cs

示例9: ExecutionContext

        public ExecutionContext(TimeSpan skipAhead = default(TimeSpan))
        {
            this.disposables = new CompositeDisposable();
            this.cancelRequested = new BehaviorSubject<bool>(false)
                .AddTo(this.disposables);
            this.progressDeltas = new Subject<TimeSpan>()
                .AddTo(this.disposables);

            this
                .cancelRequested
                .Where(x => x)
                .Subscribe(_ => this.IsCancelled = true)
                .AddTo(this.disposables);

            this
                .progressDeltas
                .Scan((running, next) => running + next)
                .Subscribe(x => this.Progress = x)
                .AddTo(this.disposables);

            this
                .WhenAnyValue(x => x.CurrentExercise)
                .Select(x => this.progressDeltas.StartWith(TimeSpan.Zero).Scan((running, next) => running + next))
                .Switch()
                .Subscribe(x => this.CurrentExerciseProgress = x)
                .AddTo(this.disposables);

            this
                .progressDeltas
                .StartWith(skipAhead)
                .Scan((running, next) => running - next)
                .Select(x => x < TimeSpan.Zero ? TimeSpan.Zero : x)
                .Subscribe(x => this.SkipAhead = x)
                .AddTo(this.disposables);
        }
开发者ID:gregjones60,项目名称:WorkoutWotch,代码行数:35,代码来源:ExecutionContext.cs

示例10: PlaySound

 public static void PlaySound(string fileName)
 {
     var disposables = new CompositeDisposable();
     var sampleProvider = GetSampleProvider(fileName, disposables);
     var wrapper = new AutoDisposeSampleProvider(sampleProvider, (IDisposable)disposables);
     AddMixerInput(wrapper);
 }
开发者ID:Kei-Nanigashi,项目名称:StarryEyes,代码行数:7,代码来源:AudioPlayer.cs

示例11: BuildConnectionToken

        public IObservable<ConnectionToken> BuildConnectionToken(string host, int port, IScheduler scheduler)
        {
            return Observable.Create<ConnectionToken>(observer =>
            {
                var disposable = new CompositeDisposable();

                var socket = socketFactory();
                var socketEvent = socketEventsFactory();

                socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
                socketEvent.SocketClientAccessPolicyProtocol = System.Net.Sockets.SocketClientAccessPolicyProtocol.Tcp;

                var connectionToken = new ConnectionToken(socket, socketEvent);

                var disposableEventSubscription = socketEvent.Completed.Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEvent, connectionToken);
                });

                var disposableActions = scheduler.Schedule(() =>
                {    
                    if (!socket.ConnectAsync(socketEvent))
                    {
                        SendNotificationToObserver(observer, socketEvent, connectionToken);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:33,代码来源:RedisConnector.cs

示例12: Receive

        public IObservable<string> Receive(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, byte[] buffer)
        {
            if (connectedSocket == null)
                throw new ArgumentNullException("connectedSocket");

            if (socketEventArgs == null)
                throw new ArgumentNullException("socketEventArgs");

            return Observable.Create<string>(observer =>
            {
                var disposable = new CompositeDisposable();

                var disposableEventSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEventArgs);
                });

                var disposableActions = scheduler.Schedule(() =>
                {
                    socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
                    if (!connectedSocket.ReceiveAsync(socketEventArgs))
                    {
                        SendNotificationToObserver(observer, socketEventArgs);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:32,代码来源:SocketReceiver.cs

示例13: SetUp

        public void SetUp()
        {
            Clock.Reset();

            disposables = new CompositeDisposable
            {
                Disposable.Create(Clock.Reset)
            };

            schedule = GetScheduleDelegate();

            commandsScheduled = new ConcurrentBag<IScheduledCommand>();
            commandsDelivered = new ConcurrentBag<IScheduledCommand>();

            var configuration = new Configuration()
                .TraceScheduledCommands() // trace to console
                .TraceScheduledCommands(
                    onScheduling: _ => { },
                    onScheduled: c => commandsScheduled.Add(c),
                    onDelivering: _ => { },
                    onDelivered: c => commandsDelivered.Add(c));

            Configure(configuration, d => disposables.Add(d));

            disposables.Add(ConfigurationContext.Establish(configuration));
        }
开发者ID:commonsensesoftware,项目名称:Its.Cqrs,代码行数:26,代码来源:CommandSchedulerIdempotencyTests.cs

示例14: SendMessage

        public IObservable<Unit> SendMessage(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, string message)
        {
            if (connectedSocket == null)
                throw new ArgumentNullException("connectedSocket");

            if (socketEventArgs == null)
                throw new ArgumentNullException("socketEventArgs");

            return Observable.Create<Unit>(observer =>
            {
                var disposable = new CompositeDisposable();
                var buffer = Encoding.UTF8.GetBytes(message);

                var disposableCompletedSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEventArgs);
                });

                var disposableActions = scheduler.Schedule(() =>
                {
                    socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
                    if (!connectedSocket.SendAsync(socketEventArgs))
                    {
                        SendNotificationToObserver(observer, socketEventArgs);
                    }
                });

                disposable.Add(disposableCompletedSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:33,代码来源:SocketTransmitter.cs

示例15: Connect

        public IObservable<Socket> Connect(string host, int port, IScheduler scheduler)
        {
            return Observable.Create<Socket>(observer =>
            {
                var disposable = new CompositeDisposable();

                var socket = socketFactory();
                var socketEvent = socketEventsFactory();

                socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
                socketEvent.UserToken = socket;

                var disposableEventSubscription = socketEvent.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
                {
                    SendNotificationToObserver(observer, socketEvent);
                });

                var disposableActions = scheduler.Schedule(() =>
                {    
                    if (!socket.ConnectAsync(socketEvent))
                    {
                        SendNotificationToObserver(observer, socketEvent);
                    }
                });

                disposable.Add(disposableEventSubscription);
                disposable.Add(disposableActions);

                return disposable;
            });
        }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:31,代码来源:SocketConnector.cs


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