Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScheduledEvent.cs
1using System;
2using Waher.Events;
3
5{
9 internal class ScheduledEvent
10 {
11 private readonly DateTime when;
12 private readonly ScheduledEventCallback eventMethod;
13 private readonly object state;
14
21 public ScheduledEvent(DateTime When, ScheduledEventCallback EventMethod, object State)
22 {
23 this.when = When;
24 this.eventMethod = EventMethod;
25 this.state = State;
26 }
27
34 public ScheduledEvent(DateTime When, ScheduledEventCallbackAsync EventMethod, object State)
35 {
36 this.when = When;
37 this.eventMethod = this.AsyncCallback;
38 this.state = new object[] { EventMethod, State };
39 }
40
41 private async void AsyncCallback(object State)
42 {
43 try
44 {
45 object[] P = (object[])State;
47 State = P[1];
48
49 if (!(Callback is null))
50 await Callback(State);
51 }
52 catch (Exception ex)
53 {
54 Log.Exception(ex);
55 }
56 }
57
61 public DateTime When => this.when;
62
66 public ScheduledEventCallback EventMethod => this.eventMethod;
67
71 public object State => this.state;
72
76 public void Execute()
77 {
78 if (!(this.eventMethod is null))
79 {
80 try
81 {
82 this.eventMethod(this.state);
83 }
84 catch (Exception ex)
85 {
86 Log.Exception(ex);
87 }
88 }
89 }
90
91 }
92}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
delegate void ScheduledEventCallback(object State)
Callback method for scheduled events.
delegate Task ScheduledEventCallbackAsync(object State)
Callback method for asynchronous scheduled events.