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


C# IScheduler.Schedule方法代码示例

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


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

示例1: CreateObservable

        public static IObservable<string> CreateObservable(string key, IScheduler scheduler)
        {
            var observable = Observable.Defer(() =>
                {
                    return Observable.Create<string>(observer =>
                   {
                       var connectionFactory = new RedisConnectionFactory();

                       return connectionFactory.CreateRedisConnection().ContinueWith<IDisposable>(task =>
                           {
                               if (task.IsFaulted)
                               {
                                   observer.OnError(task.Exception);
                                   return Disposable.Empty;
                               }

                               return scheduler.Schedule(() =>
                               {
                                   var connection = task.Result.GetOpenSubscriberChannel();
                                   task.Result.Error += (_, err) => observer.OnError(err.Exception);

                                   connection.Subscribe(key, (header, content) =>
                                   {
                                       if (header == key)
                                           observer.OnNext(Encoding.UTF8.GetString(content));
                                   });
                               });
                           });
                   });
                });

             return observable;
        }
开发者ID:g-un--,项目名称:log4net.redis,代码行数:33,代码来源:RedisLogObservable.cs

示例2: 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

示例3: 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

示例4: SendMessage

        public IObservable<Unit> SendMessage(string message, IScheduler scheduler)
        {
            return Observable.Create<Unit>(observer =>
            {
                var disposable = new CompositeDisposable();
                var buffer = Encoding.UTF8.GetBytes(message);
                connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);

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

                var disposableActions = scheduler.Schedule(() =>
                {
                    if (!connectionToken.Socket.SendAsync(connectionToken.SocketEvent))
                    {
                        SendNotificationToObserver(observer, connectionToken.SocketEvent);
                    }
                });

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

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

示例5: 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

示例6: StartLoop

        private void StartLoop(IScheduler scheduler)
        {
            //delegate allocations below - but that's fine as it's not really on the "critical path" (polled relatively infrequently) - and it's much more readable this way
            scheduler.Schedule(repeatAction => _httpListener.BeginGetContext(ar =>
            {
                try
                {
                    var httpListenerContext = _httpListener.EndGetContext(ar);
                    var request = httpListenerContext.Request;
                    var response = httpListenerContext.Response;

                    response.StatusCode = 200;
                    
                    var acceptHeader = request.Headers.Get("Accept");
                    var acceptHeaders = acceptHeader == null ? null : acceptHeader.Split(',');
                    var contentType = ScrapeHandler.GetContentType(acceptHeaders);
                    response.ContentType = contentType;

                    using (var outputStream = response.OutputStream)
                    {
                        var collected = _registry.CollectAll();
                        ScrapeHandler.ProcessScrapeRequest(collected, contentType, outputStream);
                    }

                    response.Close();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(string.Format("Error in MetricsServer: {0}", e));
                }
                repeatAction.Invoke();
            }, null));
        }
开发者ID:leodsoft,项目名称:prometheus-net,代码行数:33,代码来源:MetricServer.cs

示例7: 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

示例8: SetUp

        public void SetUp()
        {
            _scheduler = new DefaultScheduler(_bus, _taskStorage);
            _handler = new ScheduledTaskMessageHandler(_scheduler);

            var task = new ScheduledTask{Task = () => { }};
            _taskId = task.Id;
            _scheduler.Schedule(task);
        }
开发者ID:nghead,项目名称:NServiceBus,代码行数:9,代码来源:ScheduledTaskMessageHandlerTests.cs

示例9: CreateObservableWithRetry

 public static IObservable<string> CreateObservableWithRetry(string key, IScheduler scheduler)
 {
     return Observable.Create<string>(observer =>
         {
             return scheduler.Schedule(self =>
                 {
                     var observable = CreateObservable(key, scheduler);
                     var disposable = observable.Subscribe(
                         message =>
                         {
                             observer.OnNext(message);
                         }, 
                         error =>
                         {
                             scheduler.Schedule(TimeSpan.FromSeconds(10), self);
                         });
                 });
         });
 }
开发者ID:g-un--,项目名称:log4net.redis,代码行数:19,代码来源:RedisLogObservable.cs

示例10: Test2

 static void Test2(IScheduler scheduler)
 {
     var myName = "Lee";
       scheduler.Schedule(
       myName,
       (_, state) =>
       {
     Console.WriteLine("myName = {0}", state);
     return Disposable.Empty;
       });
       myName = "John";
 }
开发者ID:pudae,项目名称:lplpl,代码行数:12,代码来源:TestPassingState.cs

示例11: Tail

        //public IObservable<string> TailV2(IFile file)
        //{
        //    return ObservableFile.WatchLines(file.GetNativePath(), Encoding.Default);
        //}

        public IObservable<string> Tail(IFile file, IScheduler scheduler = null)
        {
            return Observable.Create<string>(subj =>
            {
                var disposable = new CompositeDisposable();
                scheduler = scheduler ?? RxApp.TaskpoolScheduler;
                var abortSignal = new ManualResetEvent(false);

                disposable.Add(Disposable.Create(() => abortSignal.Set()));

                disposable.Add(scheduler.Schedule(abortSignal, (sched, state) =>
                {
                    using (var reader = new StreamReader(
                        file.GetContent().OpenStream(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                    {
                        long lastOffset = reader.BaseStream.Length;
                        if (reader.BaseStream.Length > 0)
                        {
                            // Send the last 10 kb of text to the reader.
                            lastOffset = Math.Max(0, reader.BaseStream.Length - (1024 * 10));
                        }

                        while (!state.WaitOne(100))
                        {
                            // Idle if file hasn't changed.
                            if (reader.BaseStream.Length <= lastOffset)
                            {
                                if (reader.BaseStream.Length < lastOffset)
                                {
                                    lastOffset = reader.BaseStream.Length;
                                }
                                continue;
                            }

                            // Read the data.
                            reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
                            var delta = reader.BaseStream.Length - lastOffset;
                            var buffer = new char[delta];
                            reader.ReadBlock(buffer, 0, buffer.Length);

                            // Publish the data.
                            subj.OnNext(new string(buffer));

                            // Update the offset.
                            lastOffset = reader.BaseStream.Position;
                        }
                    }
                    return Disposable.Empty;
                }));

                return disposable;
            });
        }
开发者ID:kmcginnes,项目名称:SpicyTaco.ChaseTheTail,代码行数:58,代码来源:TailService.cs

示例12: ScheduleTasks

        private static string[] ScheduleTasks(IScheduler scheduler)
        {
            var list = new List<string>();

            Action leafAction = () => list.Add("----leafAction.");
            Action innerAction = () =>
            {
                list.Add("--innerAction start.");
                scheduler.Schedule(leafAction);
                list.Add("--innerAction end.");
            };
            Action outerAction = () =>
            {
                list.Add("outer start.");
                scheduler.Schedule(innerAction);
                list.Add("outer end.");
            };
            scheduler.Schedule(outerAction);

            return list.ToArray();
        }
开发者ID:createdbyx,项目名称:UniRx,代码行数:21,代码来源:SchedulerTest.cs

示例13: Test

 static void Test(IScheduler scheduler, bool testCancel = false)
 {
     Console.WriteLine("Before schedule at {0:o}", DateTime.Now);
       var token = scheduler.Schedule(
       TimeSpan.FromSeconds(1),
       () => Console.WriteLine("Inside schedule at {0:o}", DateTime.Now));
       Console.WriteLine("After schedule at {0:o}", DateTime.Now);
       if (testCancel)
       {
     Console.WriteLine("Cancel schedule at {0:o}", DateTime.Now);
     token.Dispose();
       }
 }
开发者ID:pudae,项目名称:lplpl,代码行数:13,代码来源:TestFutureScheduling.cs

示例14: Test

        static void Test(IScheduler scheduler)
        {
            Action<Action> work = self =>
              {
            Console.WriteLine("Running");
            self();
              };

              var token = scheduler.Schedule(work);
              Console.ReadLine();
              Console.WriteLine("Cancelling");
              token.Dispose();
              Console.WriteLine("Cancelled");
        }
开发者ID:pudae,项目名称:lplpl,代码行数:14,代码来源:TestRecursion.cs

示例15: FolderNode

        public FolderNode(string path, IScheduler loadScheduler, IScheduler dispatherScheduler, FolderNode parent)
            : base(path, parent)
        {
            _loadScheduler = loadScheduler;
            _dispatherScheduler = dispatherScheduler;

            IsLoaded = false;

            var directoryInfo = new DirectoryInfo(path);
            _name = directoryInfo.Name;
            CreatedDate = directoryInfo.CreationTimeUtc;


            _loadScheduler.Schedule(LoadChildren);
        }
开发者ID:VisualFinance,项目名称:VisualFinance.Windows,代码行数:15,代码来源:FolderNode.cs


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