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


C# IObserver.OnError方法代码示例

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


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

示例1: FetchBytes

        static IEnumerator FetchBytes(WWW www, IObserver<byte[]> observer, IProgress<float> reportProgress, CancellationToken cancel)
        {
            using (www)
            {
                while (!www.isDone && !cancel.IsCancellationRequested)
                {
                    if (reportProgress != null)
                    {
                        try
                        {
                            reportProgress.Report(www.progress);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            yield break;
                        }
                    }
                    yield return null;
                }

                if (cancel.IsCancellationRequested) yield break;

                if (!string.IsNullOrEmpty(www.error))
                {
                    observer.OnError(new Exception(www.error));
                }
                else
                {
                    observer.OnNext(www.bytes);
                    observer.OnCompleted();
                }
            }
        }
开发者ID:hoghweed,项目名称:LightNode,代码行数:34,代码来源:ObservableWWW.cs

示例2: RunAsync

        public async Task RunAsync(IObserver<string> observer)
        {
            var urls = new[]
            {
                "http://yahoo.co.jp",
                "http://google.co.jp",
                "http://bing.co.jp",
                "http://awsedrftgyhujikol.jp/",
            };

            foreach (var url in urls)
            {
                await Observable.Timer(TimeSpan.FromSeconds(1));

                try
                {
                    var res = await GetAsStringAsync(url);
                    observer.OnNext(res);
                }
                catch(Exception ex)
                {
                    observer.OnError(ex);
                }
            }
        }
开发者ID:ufcpp,项目名称:AwaitableUniRx,代码行数:25,代码来源:Class1.cs

示例3: MainAsync

        public static async Task MainAsync(IObserver<string> observer)
        {
            observer.OnNext("start");
            await I.Task.Delay(delay);
            observer.OnNext("1");
            await Observable.Timer(delay);
            observer.OnNext("2");
            await Task.Delay(delay);
            observer.OnNext("3");

            await I.Task.Delay(delay);

            var urls = new[]
            {
                "http://yahoo.co.jp",
                "http://google.co.jp",
                "http://bing.co.jp",
                "http://awsedrftgyhujikol.jp/",
            };

            foreach (var url in urls)
            {
                try
                {
                    var res = await GetAsStringAsync(url);
                    observer.OnNext(res);
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);
                }
            }

            observer.OnCompleted();
        }
开发者ID:ch896,项目名称:MinimumAsyncBridge,代码行数:35,代码来源:Class1.cs

示例4: Accept

        bool Accept(IObserver<Interactor> observer)
        {
            Log.Info("Accept new connection");

            try
            {
                var newSocket = _listener.Accept();
                var interactor = new Interactor(newSocket, _nextInteractorId++, _bufferManager);
                _interactors.Add(newSocket, interactor);
                Log.DebugFormat("Accepted {0}", interactor);
                observer.OnNext(interactor);
                return true;
            }
            catch (SocketException ex)
            {
                if (ex.SocketErrorCode == SocketError.Interrupted)
                    observer.OnCompleted();
                else
                    observer.OnError(ex);
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }

            return false;
        }
开发者ID:rob-blackbourn,项目名称:TopicBus,代码行数:27,代码来源:Acceptor.cs

示例5: SuccessTest

 /// <summary>
 /// This will test if the exception has an error code that is not 0 (0 is success), if it does then it sends the observer an OnError.
 /// </summary>
 /// <param name="observer">
 /// The observer.
 /// </param>
 public void SuccessTest(IObserver<IUsbDeviceNotification> observer)
 {
     if (!Win32Error.IsSuccess)
     {
         observer.OnError(Win32Error.Exception);
     }
 }
开发者ID:RichardWilliams,项目名称:WinUsbRx,代码行数:13,代码来源:ProcessHandleResult.cs

示例6: SendNotificationToObserver

 private void SendNotificationToObserver(IObserver<string> observer, SocketAsyncEventArgs socketEvent)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         if (socketEvent.BytesTransferred == 0)
         {
             observer.OnError(new InvalidOperationException("Received no bytes from Redis"));
         }
         else
         {
             observer.OnNext(Encoding.UTF8.GetString(socketEvent.Buffer, 0, socketEvent.BytesTransferred));
             observer.OnCompleted();
         }
     }
     else
     {      
         observer.OnError(new RedisException(socketEvent.SocketError));
     }
 }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:19,代码来源:SocketReceiver.cs

示例7: SendNotificationToObserver

 private void SendNotificationToObserver(IObserver<Unit> observer, SocketAsyncEventArgs socketEvent)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         observer.OnNext(Unit.Default);
         observer.OnCompleted();
     }
     else
     {
         observer.OnError(new RedisException(socketEvent.SocketError));
     }
 }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:12,代码来源:SocketTransmitter.cs

示例8: SendNotificationToObserver

 private void SendNotificationToObserver(IObserver<ConnectionToken> observer, ISocketAsyncEventArgs socketEvent, ConnectionToken connectionToken)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         observer.OnNext(connectionToken);
         observer.OnCompleted();
     }
     else
     {
         observer.OnError(new RedisException(socketEvent.SocketError));
     }
 }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:12,代码来源:RedisConnector.cs

示例9: SendNotificationToObserver

 private bool SendNotificationToObserver(IObserver<string> observer, ISocketAsyncEventArgs socketEvent)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         observer.OnNext(Encoding.UTF8.GetString(socketEvent.Buffer, 0, socketEvent.BytesTransferred));
         return true;
     }
     else
     {
         observer.OnError(new RedisException(socketEvent.SocketError));
         return false;
     }
 }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:13,代码来源:RedisReceiver.cs

示例10: CreateProcessExitSubscription

		private IDisposable CreateProcessExitSubscription(Process process, IObservable<EventPattern<object>> processExited, IObserver<string> observer)
		{
			return processExited.Subscribe(args =>
			{
				try
				{
					if (process?.ExitCode > 0)
					{
						observer.OnError(new Exception(
							$"Process '{process.StartInfo.FileName}' terminated with error code {process.ExitCode}"));
					}
					else observer.OnCompleted();
				}
				finally
				{
					this.Started = false;
					process?.Close();
				}
			});
		}
开发者ID:michaelbudnik,项目名称:elasticsearch-net,代码行数:20,代码来源:ObservableProcess.cs

示例11: GetWWWCore

        // IEnumerator with callback
        static IEnumerator GetWWWCore(string url, IObserver<string> observer, CancellationToken cancellationToken)
        {
            var www = new UnityEngine.WWW(url);
            while (!www.isDone && !cancellationToken.IsCancellationRequested)
            {
                yield return null;
            }

            if (cancellationToken.IsCancellationRequested) yield break;

            if (www.error != null)
            {
                observer.OnError(new Exception(www.error));
            }
            else
            {
                observer.OnNext(www.text);
                observer.OnCompleted();
            }
        }
开发者ID:iodandidiot,项目名称:Game1,代码行数:21,代码来源:Sample05_ConvertFromCoroutine.cs

示例12: RunObservable

 private static IDisposable RunObservable(IDbCommand command, IDbConnection connection, IDataReader reader,
                                      IDictionary<string, int> index, IObserver<IDictionary<string, object>> o)
 {
     try
     {
         while (reader.Read())
         {
             o.OnNext(reader.ToDictionary(index));
         }
         o.OnCompleted();
     }
     catch (Exception ex)
     {
         o.OnError(ex);
     }
     finally
     {
         DisposeCommandAndReader(connection, command, reader);
     }
     return ColdObservable.EmptyDisposable;
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:21,代码来源:IObservableQueryRunner.cs

示例13: ReadStreamToEnd

        static async Task ReadStreamToEnd(StreamReader stream, IObserver<string> observable) {
            try {
                var readBuffer = new char[1];
                var lineBuffer = new StringBuilder();
                while (await stream.ReadAsync(readBuffer, 0, 1).ConfigureAwait(false) > 0) {
                    var c = readBuffer[0];
                    lineBuffer.Append(c);
                    // This does not account for unterminated lines.... like 'verifying download...'
                    // We would be able to do this by sending the data also byte by byte to the receivers, but for little gain.
                    if ((c != '\r') && (c != '\n'))
                        continue;
                    observable.OnNext(lineBuffer.ToString());
                    lineBuffer.Clear();
                }

                if (lineBuffer.Length > 0)
                    observable.OnNext(lineBuffer.ToString());
                observable.OnCompleted();
            } catch (Exception ex) {
                observable.OnError(ex);
                throw;
            }
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:23,代码来源:ReactiveProcess.cs

示例14: AsObservableCore

        static IEnumerator AsObservableCore(AsyncOperation asyncOperation, IObserver<AsyncOperation> observer, IProgress<float> reportProgress, CancellationToken cancel)
        {
            while (!asyncOperation.isDone && !cancel.IsCancellationRequested)
            {
                if (reportProgress != null)
                {
                    try
                    {
                        reportProgress.Report(asyncOperation.progress);
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                        yield break;
                    }
                }
                yield return null;
            }

            if (cancel.IsCancellationRequested) yield break;

            observer.OnNext(asyncOperation);
            observer.OnCompleted();
        }
开发者ID:Lisy09Personal,项目名称:UnityChanRoadRx,代码行数:24,代码来源:AsyncOperationExtensions.cs

示例15: Producer4

        Task Producer4(IObserver<int> results, CancellationToken token, IScheduler scheduler, Exception exception)
        {
            var tcs = new TaskCompletionSource<object>();

            var x = 0;

            var d = scheduler.Schedule(TimeSpan.FromTicks(100), self =>
            {
                if (x == 4)
                {
                    results.OnError(exception);
                }
                results.OnNext(++x);
                self(TimeSpan.FromTicks(100));
            });

            token.Register(d.Dispose);

            return tcs.Task;
        }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:20,代码来源:ObservableCreationTest.cs


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