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


C# Subject.Dispose方法代码示例

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


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

示例1: InitialiStatusIsLoadding

 public void InitialiStatusIsLoadding()
 {
     bool invoked=false;
     var status=ConnectionStatus.Pending;
     var subscription = new Subject<int>().MonitorStatus().Subscribe(s=>
         {
             invoked = true;
         status = s;
     });
     Assert.IsTrue(invoked, "No status has been received");
     Assert.AreEqual(ConnectionStatus.Pending,status, "No status has been received");
     subscription.Dispose();
 }
开发者ID:oysteinkrog,项目名称:DynamicData,代码行数:13,代码来源:MonitorStatusFixture.cs

示例2: LoadBytes

 private static async Task LoadBytes(Uri source, Subject<byte[]> subject)
 {
     var client = new HttpClient();
     try
     {
         byte[] result;
         Func<Uri, byte[]> resolver;
         if (source.Scheme != "http" && source.Scheme != "https" &&
             _specialTable.TryGetValue(source.Scheme, out resolver))
         {
             result = resolver(source);
         }
         else
         {
             var errorCount = 0;
             while (true)
             {
                 errorCount++;
                 try
                 {
                     using (var response = await client.GetAsync(source))
                     {
                         result = await response.Content.ReadAsByteArrayAsync();
                     }
                 }
                 catch (Exception ex)
                 {
                     if (errorCount > MaxRetryCount)
                     {
                         System.Diagnostics.Debug.WriteLine("could not load:" + source + Environment.NewLine +
                                                            ex.Message);
                         throw;
                     }
                     System.Diagnostics.Debug.WriteLine(ex.ToString());
                     continue;
                 }
                 break;
             }
         }
         SetCache(source, result);
         lock (_imageObservables)
         {
             _imageObservables.Remove(source);
         }
         subject.OnNext(result);
         subject.OnCompleted();
     }
     catch (Exception ex)
     {
         lock (_imageObservables)
         {
             _imageObservables.Remove(source);
         }
         subject.OnError(ex);
         subject.Dispose();
     }
     finally
     {
         client.Dispose();
     }
 }
开发者ID:Mojopon,项目名称:StarryEyes,代码行数:61,代码来源:LazyImage.cs

示例3: SubjectSubscribeTest

        public void SubjectSubscribeTest()
        {
            var subject = new Subject<int>();
            var listA = new List<int>();
            var listB = new List<int>();
            var listC = new List<int>();
            subject.HasObservers.IsFalse();

            var listASubscription = subject.Subscribe(x => listA.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(1);
            listA[0].Is(1);

            var listBSubscription = subject.Subscribe(x => listB.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(2);
            listA[1].Is(2);
            listB[0].Is(2);

            var listCSubscription = subject.Subscribe(x => listC.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(3);
            listA[2].Is(3);
            listB[1].Is(3);
            listC[0].Is(3);

            listASubscription.Dispose();
            subject.HasObservers.IsTrue();
            subject.OnNext(4);
            listA.Count.Is(3);
            listB[2].Is(4);
            listC[1].Is(4);

            listCSubscription.Dispose();
            subject.HasObservers.IsTrue();
            subject.OnNext(5);
            listC.Count.Is(2);
            listB[3].Is(5);

            listBSubscription.Dispose();
            subject.HasObservers.IsFalse();
            subject.OnNext(6);
            listB.Count.Is(4);

            var listD = new List<int>();
            var listE = new List<int>();

            subject.Subscribe(x => listD.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(1);
            listD[0].Is(1);

            subject.Subscribe(x => listE.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(2);
            listD[1].Is(2);
            listE[0].Is(2);

            subject.Dispose();

            AssertEx.Throws<ObjectDisposedException>(() => subject.OnNext(0));
            AssertEx.Throws<ObjectDisposedException>(() => subject.OnError(new Exception()));
            AssertEx.Throws<ObjectDisposedException>(() => subject.OnCompleted());
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:64,代码来源:UnitTests.cs

示例4: HasObservers_Dispose3

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

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:8,代码来源:SubjectTest.cs

示例5: HasObservers_Dispose2

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

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

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

            s.Dispose();
            Assert.IsFalse(s.HasObservers);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:14,代码来源:SubjectTest.cs

示例6: Send

 public IObservable<TweetInputInfo> Send()
 {
     var postResults = new List<PostResult>();
     var subject = new Subject<TweetInputInfo>();
     var request = MessageRecipient != null
                       ? (RequestBase<TwitterStatus>)new MessagePostingRequest(MessageRecipient, Text)
                       : new TweetPostingRequest(Text, InReplyTo != null ? InReplyTo.Status : null,
                                                 AttachedGeoInfo, AttachedImage);
     this._accounts.ToObservable()
         .SelectMany(account => RequestQueue.Enqueue(account, request)
                                            .Do(StatusInbox.Queue)
                                            .Select(_ => new PostResult(account, _))
                                            .Catch(
                                                (Exception ex) =>
                                                Observable.Return(new PostResult(account, ex))))
         .Subscribe(postResults.Add,
                    () =>
                    {
                        // ReSharper disable AccessToDisposedClosure
                        postResults.GroupBy(_ => _.IsSucceeded)
                                   .ForEach(_ =>
                                   {
                                       if (_.Key)
                                       {
                                           var ret = Clone();
                                           ret.Accounts = _.Select(pr => pr.Account).ToArray();
                                           ret.PostedTweets =
                                               _.Select(pr => Tuple.Create(pr.Account, pr.Status))
                                                .ToArray();
                                           subject.OnNext(ret);
                                       }
                                       else
                                       {
                                           _.ForEach(pr =>
                                           {
                                               var ret = Clone();
                                               ret.Accounts = new[] { pr.Account };
                                               ret.ThrownException = pr.ThrownException;
                                               subject.OnNext(ret);
                                           });
                                       }
                                   });
                        // ReSharper restore AccessToDisposedClosure
                        subject.OnCompleted();
                        subject.Dispose();
                    });
     return subject;
 }
开发者ID:hosiminn,项目名称:StarryEyes,代码行数:48,代码来源:InputAreaModel.cs

示例7: Send

 public IObservable<TweetInputInfo> Send()
 {
     var postResults = new List<PostResult>();
     var subject = new Subject<TweetInputInfo>();
     _authInfos.ToObservable()
               .SelectMany(authInfo =>
                           (MessageRecipient != null
                                ? (OperationBase<TwitterStatus>)
                                  new DirectMessageOperation(authInfo, MessageRecipient, Text)
                                : new TweetOperation(authInfo, Text, InReplyTo, AttachedGeoInfo, AttachedImage)
                           ).Run()
                            .SelectMany(StoreHub.MergeStore)
                            .Select(_ => new PostResult(authInfo, _))
                            .Catch((Exception ex) => Observable.Return(new PostResult(authInfo, ex))))
               .Subscribe(postResults.Add,
                          () =>
                          {
                              postResults.GroupBy(_ => _.IsSucceeded)
                                         .ForEach(_ =>
                                         {
                                             if (_.Key)
                                             {
                                                 TweetInputInfo ret = Clone();
                                                 ret.AuthInfos = _.Select(pr => pr.AuthInfo).ToArray();
                                                 ret.PostedTweets =
                                                     _.Select(pr => Tuple.Create(pr.AuthInfo, pr.Status))
                                                      .ToArray();
                                                 subject.OnNext(ret);
                                             }
                                             else
                                             {
                                                 _.ForEach(pr =>
                                                 {
                                                     TweetInputInfo ret = Clone();
                                                     ret.AuthInfos = new[] { pr.AuthInfo };
                                                     ret.ThrownException = pr.ThrownException;
                                                     subject.OnNext(ret);
                                                 });
                                             }
                                         });
                              subject.OnCompleted();
                              subject.Dispose();
                          });
     return subject;
 }
开发者ID:Aeri912,项目名称:StarryEyes,代码行数:45,代码来源:InputAreaModel.cs


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