private void Handle(ThreadStatusChanged evnt)
 {
     using (var conn = _connectionFactory.OpenConnection())
     {
         conn.Update(
             new { Status = evnt.Status, },
             new { Id = evnt.Id },
             "EventSourcing_Sample_Thread");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Worker Thread function.
        /// </summary>
        /// <remarks>
        /// The usual form of a Saint Program that sends messages allows the
        /// user to start and stop the sending of messages.
        /// WITH THIS IN MIND, the Execution task should expect to be paused
        /// when there are no messages to send and the user has indicated
        /// to stop sending messages. This should be handled appropriately.
        /// ADDITIONALLY, there are usually messages being sent on an interval
        /// of at most 1 second intervals, sometimes on 10ms intervals, and this
        /// scenario should also be handled appropriately.
        /// </remarks>
        private Task ExecutionTask(CancellationToken token)
        {
            return(new Task(() =>
            {
                int previousSleep = 0;
                while (!token.IsCancellationRequested)
                {
                    // Notify the handle that the tasks have been depleted.
                    ThreadStatus = ThreadStatusValue.Waiting;
                    ThreadStatusChanged?.Invoke(this, new EventArgs());

                    try
                    {
                        // Wait here to avoid spinning when user pauses.
                        if (!_tasks.TryTake(out QueueTask task_, int.MaxValue, token))
                        {
                            continue;
                        }

                        task_.Execute(Sender, previousSleep);
                        previousSleep = task_.Sleep;

                        // Notify the handle that the tasks are being processed.
                        // (Do this after Execution to avoid any slowdown.)
                        ThreadStatus = ThreadStatusValue.Busy;
                        ThreadStatusChanged?.Invoke(this, new EventArgs());

                        // Get the enumerable to iterate over consecutive messages.
                        foreach (QueueTask task in _tasks.GetConsumingEnumerable(token))
                        {
                            task.Execute(Sender, previousSleep);
                            previousSleep = task.Sleep;
                        }
                    }
                    catch (TaskCanceledException) { return; }
                }
            }));
        }
 protected virtual void Handle(ThreadStatusChanged evnt)
 {
     var thread = _entityManager.GetById<ThreadEntity>(evnt.Id);
     _entityManager.UpdateAndSave<ThreadStatusChanged>(thread, evnt, x => x.Status);
 }
        protected virtual void Handle(ThreadStatusChanged evnt)
        {
            var thread = _entityManager.GetById <ThreadEntity>(evnt.Id);

            _entityManager.UpdateAndSave <ThreadStatusChanged>(thread, evnt, x => x.Status);
        }
 /// <summary>
 /// 通知服务工作线程状态发生变更。
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnThreadStatusChanged(ServiceThreadStatusChangedEventArgs <TTask> e)
 {
     ThreadStatusChanged?.Invoke(e);
 }