protected virtual async Task OnWorkCompletedAsync(int result, bool runSynchronously, CancellationToken cancellationToken) => await WorkCompleted.RaiseAsync( new TestSyncAsyncEventArgs(this, result, runSynchronously, cancellationToken), nameof(TestClient), nameof(Working), ClientDiagnostics) .ConfigureAwait(false);
public void DoWork() { Console.WriteLine("Worker: work started"); if (this.Started != null) { this.Started(); } Console.WriteLine("Worker: work progressing"); if (this.Progressing != null) { this.Progressing(); } Console.WriteLine("Worker: work completed"); if (this.Completed != null) { foreach (WorkCompleted wc in this.Completed.GetInvocationList()) { WorkCompleted wc2 = wc; wc.BeginInvoke(delegate(IAsyncResult result) { int grade = wc2.EndInvoke(result); Console.WriteLine("Worker grade= {0}", grade); }, null); } } }
private void Work() { if (workItems.Count == 0) { //Wait for signal //... Just to be sure! while (workItems.Count == 0) { startSignal.WaitOne(); } } while (workItems.Count > 0) { //Gets the item from queue, does its work & repeats var item = workItems.Dequeue(); //Inform about the work WorkItemStarted?.Invoke(this, item); //Start the work item.Work.Invoke(this); //Inform about job being done WorkItemCompleted?.Invoke(this, item); } //Inform about DONE! WorkCompleted?.Invoke(this); }
public void Start(Task task, int seconds) { Thread.Sleep((_delay + seconds) * 1000); var result = $"Task with type: {task} completed after {_delay + seconds} seconds from worker {_number}"; WorkCompleted?.Invoke(result); }
private void Runner() { CancellationTokenSource?.Dispose(); CancellationTokenSource = new CancellationTokenSource(); CancellationToken = CancellationTokenSource.Token; MessageDataItem message = null; while (true) { if (SpinWait.SpinUntil(() => AttachedQueue.TryTake(out message), 1)) { ProcessMessage(message); // assume there are more messages // NB! No need to test CancellationToken in this loop, because it's a kind of attempt to drain the queue. If not achieved in-time, // will be terminated forcibly. while (AttachedQueue.TryTake(out message)) { ProcessMessage(message); } } // no messages left if (CancellationToken.IsCancellationRequested) { break; } } // All done, but let's drain the queue -- if anything left it will never be completed while (AttachedQueue.Count > 0) { Thread.Sleep(5); } WorkCompleted.Set(); }
void WorkGraded(IAsyncResult res) { WorkCompleted wc = (WorkCompleted)res.AsyncState; int grade = wc.EndInvoke(res); Console.WriteLine("Worker grade = " + grade); }
public void DoWork() { DoingWork = true; DoWorkImplementation(); DoingWork = false; WorkCompleted?.Invoke(); }
/// <summary> /// Used to invoke the <see cref="WorkCompleted" /> event /// </summary> /// <param name="args">The TCompletedArgs to send in the event</param> private void OnCompleted(TCompletedArgs args) { LogInformation("Worker completed at {0}", DateTime.Now); if (WorkCompleted != null) { WorkCompleted.BeginInvoke(this, args, iar => WorkCompleted.EndInvoke(iar), null); } }
protected virtual void OnWorkCompleted(int hours) { WorkPerformedEventArgs wpea = new WorkPerformedEventArgs { Hours = hours }; WorkCompleted?.Invoke(this, wpea); }
public virtual void DoWork(int hours, WorkType workType) { for (int i = 0; i < hours; i++) { WorkPerformed.Invoke(i + 1, workType); } WorkCompleted.Invoke(this, new WorkCompletedEventsArgs(hours, workType)); }
/// <summary> /// Used to invoke the <see cref="WorkCompleted" /> event /// </summary> /// <param name="args">The TCompletedArgs to send in the event</param> private void OnCompleted(TCompletedArgs args) { logger.Log(LogLevel.Information, this, string.Format("Worker completed at {0}", DateTime.Now)); if (WorkCompleted != null) { WorkCompleted.BeginInvoke(this, args, iar => WorkCompleted.EndInvoke(iar), null); } }
public void Handle(WorkCompleted message) { if (!string.IsNullOrEmpty(message.Job)) { SimpleLogger.End(message.Job); } count--; NotifyOfPropertyChange(() => IsBusy); }
public WorkAgentObserver ( WorkSubmitted WorkSubmitted, WorkDispatched WorkDispatched, WorkCompleted WorkCompleted ) { this.WorkSubmitted = WorkSubmitted; this.WorkDispatched = WorkDispatched; this.WorkCompleted = WorkCompleted; }
public void Completed() { WorkCompleted workCompleted = this.ProcessCompletedEvent; if (workCompleted == null) { return; } SchedulerClient schedulerClient = this; workCompleted(ref schedulerClient); }
void IHandle <WorkCompleted> .Handle(WorkCompleted message) { var job = message.Job; if (!string.IsNullOrEmpty(job)) { SimpleLogger.End(job); } ActiveTasks.Remove(job ?? "unknown"); count--; NotifyOfPropertyChange(() => IsBusy); }
public WorkCommandAgentObserver ( WorkSubmitted <TSpec> WorkSubmitted, WorkDispatched <TSpec> WorkDispatched, WorkCompleted <TSpec> WorkCompleted ) : base ( work => WorkSubmitted?.Invoke(work.Command), work => WorkDispatched?.Invoke(work.Command), work => WorkCompleted?.Invoke(work.Command) ) { }
public void DoWork(int hours, WorkType type) { for (int i = 0; i < hours; i++) { if (WorkPerformed != null) { WorkPerformed.Invoke(i + 1, type); } } if (WorkCompleted != null) { WorkCompleted.Invoke(this, new WorkCompletedEventArgs(hours, type)); } }
public WorkAgentObserver ( WorkGroupSubmitted GroupSubmitted = null, WorkGroupCompleted GroupCompleted = null, WorkSubmitted WorkSubmitted = null, WorkDispatched WorkDispatched = null, WorkCompleted WorkCompleted = null ) { this.GroupSubmitted = GroupSubmitted; this.GroupCompleted = GroupCompleted; this.WorkSubmitted = WorkSubmitted; this.WorkDispatched = WorkDispatched; this.WorkCompleted = WorkCompleted; }
// using the approach where you explicitly define a handler. //public event SubscribeNotifyHandler SubscribeToNotifications; //public delegate void SubscribeNotifyHandler(object sender, MyCustomEventArgs args); /// <summary> /// Do some work and when done, raise a notification. /// </summary> /// <param name="str"></param> /// <returns></returns> public int DoSomeWork(string str) { for (int i = 0; i < 5; i++) { System.Threading.Thread.Sleep(2000); Console.WriteLine($"\nIn DoSomeWork(): Raising OnWorkEventRaiser({str})"); // raise the event which in turn will signal all the subscribers; can pass back // data in the CustomEventArgs SubscribeToNotifications?.Invoke(this, new MyCustomEventArgs("Responding to work done.")); } // raise completion event WorkCompleted?.Invoke(this, new MyCustomEventArgs("Work has finished.")); return(1); }
public void Start(Task task, int seconds) { var totalseconds = _delay + seconds; for (var i = 0; i < totalseconds; i++) { Thread.Sleep(1 * 1000); WorkExecuting?.Invoke(this, EventArgs.Empty); } var args = new WorkCompletedEventArgs($"Task with type: {task} completed after {totalseconds} seconds from worker {_number}", totalseconds); WorkCompleted?.Invoke(this, args); }
public WorkCommandAgentObserver ( WorkGroupSubmitted GroupSubmitted = null, WorkGroupCompleted GroupCompleted = null, WorkSubmitted <TSpec> WorkSubmitted = null, WorkDispatched <TSpec> WorkDispatched = null, WorkCompleted <TSpec> WorkCompleted = null ) : base ( GroupSubmitted, GroupCompleted, work => WorkSubmitted?.Invoke(work.Command), work => WorkDispatched?.Invoke(work.Command), work => WorkCompleted?.Invoke(work.Command) ) { }
async Task BeginWork() { WorkBeginning?.Invoke("Bullshit", null); TotalRecordsToProcess = uow.Query <Location>().Count() + uow.Query <Cable>().Count() + uow.Query <Conduit>().Count() + uow.Query <MiscFacility>().Count(); if (!string.IsNullOrWhiteSpace(TbCmsConnectionStringText) && !string.IsNullOrWhiteSpace(tbOracleConnectionStringText)) { await Task.WhenAll( HandleStep2 <Location>("Locations"), HandleStep2 <Cable>("Cables"), HandleStep2 <Conduit>("Conduits"), HandleStep2 <MiscFacility>("Miscfacilitys")); } WorkCompleted?.Invoke("No More Bullshit", null); }
public void DoWork(int hours, WorkType workType) { for (int i = 0; i < hours; i++) { if (workType == WorkType.Work) { Console.WriteLine("$$$$$$$$$$$$$"); } else if (workType == WorkType.DoNothing) { Console.WriteLine("Zzzzz..."); } //WorkPerfomed WorkPerfomed?.Invoke(this, new WorkInfo(workType, hours)); } //WorkCompleted; WorkCompleted?.Invoke(this, EventArgs.Empty); //? - вызвать если не null }
public void DoWork(int hours, WorkType workType) { //if (WorkStarted != null) // WorkStarted(hours, workType); WorkStarted?.Invoke(hours, workType); for (int i = 0; i < hours; i++) { System.Threading.Thread.Sleep(500); //if (WorkPieceDone != null) // WorkPieceDone(i + 1, workType); //WorkPerformed?.Invoke(i + 1, workType); OnWorkPerformed(i + 1, workType); } //Console.WriteLine($"{i+1} hours done"); //if (WorkCompleted != null) // WorkCompleted(this, EventArgs.Empty); WorkCompleted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Simulates the employee working on a task. /// </summary> /// <returns>A <c>Task</c> with details of the operation.</returns> public virtual async Task DoWork() { /* This is one way of running an asynchronous operation. Program execution will * continue along while this completes on a separate thread. */ await Task.Run(() => { // Simulate doing your work here. A real-life scenario could be making a HTTP request or database query. Console.WriteLine($"{Name}: Doing my work now..."); Thread.Sleep(5000); /* Fire the event, notifying all subscribers. This event handler will be null if no one * is subscribing to it. Can also override the sender with any object or variable type. */ if (WorkCompleted != null) { WorkCompleted.Invoke(Name, new WorkEventArgs("I've completed my work!")); } else { Console.WriteLine($"{Name}: Moving on to something else now..."); } }); }
protected virtual void OnWorkCompleted() { WorkCompleted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Checks if our event handler has any subscribers matching the argument. /// </summary> /// <param name="methodName">The method name to search for.</param> /// <returns>True if there is a matched method subscribed to this event.</returns> /// <remarks><c>GetInvocationList() must be called within the class having the event handler.</c></remarks> public bool HasMethodAsEventHandler(string methodName) { return((bool)WorkCompleted? .GetInvocationList() .Any(i => string.Equals(i.Method.Name, methodName, StringComparison.InvariantCultureIgnoreCase))); }
protected virtual void OnWorkCompleted(object sender, EventArgs e) { WorkCompleted?.Invoke(sender, e); }
private void ApplyQuery() { TweetSearcher.Query = Query; WorkCompleted?.Invoke(this, EventArgs.Empty); }
private void OnWorkerCompleted() { WorkCompleted?.Invoke(this, EventArgs.Empty); //if (WorkCompleted is EventHandler del) // del(this, EventArgs.Empty); }