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 System.Threading.Tasks;
3using Waher.Events;
4
6{
10 internal class ScheduledEvent
11 {
12 private readonly DateTime when;
13 private readonly Action<object> eventMethod;
14 private readonly object state;
15
22 public ScheduledEvent(DateTime When, Action<object> EventMethod, object State)
23 {
24 this.when = When;
25 this.eventMethod = EventMethod;
26 this.state = State;
27 }
28
35 public ScheduledEvent(DateTime When, Func<object, Task> EventMethod, object State)
36 {
37 this.when = When;
38 this.eventMethod = this.AsyncCallback;
39 this.state = new object[] { EventMethod, State };
40 }
41
42 private async void AsyncCallback(object State)
43 {
44 try
45 {
46 object[] P = (object[])State;
47 Func<object, Task> Callback = (Func<object, Task>)P[0];
48 State = P[1];
49
50 if (!(Callback is null))
51 await Callback(State);
52 }
53 catch (Exception ex)
54 {
55 Log.Exception(ex);
56 }
57 }
58
62 public DateTime When => this.when;
63
67 public Action<object> EventMethod => this.eventMethod;
68
72 public object State => this.state;
73
77 public void Execute()
78 {
79 if (!(this.eventMethod is null))
80 {
81 try
82 {
83 this.eventMethod(this.state);
84 }
85 catch (Exception ex)
86 {
87 Log.Exception(ex);
88 }
89 }
90 }
91
92 }
93}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
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:1657