Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LoadableService.cs
2{
5 {
6 //private SemaphoreSlim worker = new SemaphoreSlim(1, 1);
7
11 public bool IsLoaded { get; protected set; }
12
16 public bool IsLoading { get; protected set; }
17
21 public bool IsUnloading { get; protected set; }
22
26 public bool IsResuming { get; protected set; }
27
34 protected bool BeginLoad(bool IsResuming, CancellationToken CancellationToken)
35 {
36 //this.worker.Wait();
37
38 if (this.IsLoaded)
39 {
40 //this.worker.Release();
41 return false;
42 }
43
44 this.IsLoading = true;
45 this.IsResuming = IsResuming;
46
47 CancellationToken.ThrowIfCancellationRequested();
48
49 return true;
50 }
51
57 protected void EndLoad(bool isLoaded)
58 {
59 this.IsLoaded = isLoaded;
60 this.IsLoading = false;
61
62 //this.worker.Release();
63
64 this.OnLoaded(new LoadedEventArgs(this.IsLoaded, this.IsResuming));
65 }
66
71 protected bool BeginUnload()
72 {
73 //this.worker.Wait();
74
75 if (!this.IsLoaded)
76 {
77 //this.worker.Release();
78 return false;
79 }
80
81 this.IsUnloading = true;
82
83 return true;
84 }
85
90 protected void EndUnload()
91 {
92 this.IsLoaded = false;
93 this.IsUnloading = false;
94
95 //this.worker.Release();
96
97 this.OnLoaded(new LoadedEventArgs(this.IsLoaded, this.IsResuming));
98 }
99
101 public virtual Task Load(bool isResuming, CancellationToken cancellationToken)
102 {
103 return Task.CompletedTask;
104 }
105
107 public virtual Task Unload()
108 {
109 return Task.CompletedTask;
110 }
111
112 private event EventHandler<LoadedEventArgs>? PrivLoaded;
113
115 public event EventHandler<LoadedEventArgs> Loaded
116 {
117 add
118 {
119 PrivLoaded += value;
120 value(this, new LoadedEventArgs(this.IsLoaded, this.IsResuming));
121 }
122 remove
123 {
124 PrivLoaded -= value;
125 }
126 }
127
128 private void OnLoaded(LoadedEventArgs e)
129 {
130 PrivLoaded?.Invoke(this, e);
131 }
132 }
133}
bool IsUnloading
Gets whether the service is being unloaded.
bool BeginLoad(bool IsResuming, CancellationToken CancellationToken)
Sets the IsLoading flag if the service isn't already loading.
virtual Task Unload()
Unloads the specified service.
bool IsLoading
Gets whether the service is being loaded.
void EndLoad(bool isLoaded)
Sets the IsLoading and IsLoaded flags and fires an event representing the current load state of the s...
virtual Task Load(bool isResuming, CancellationToken cancellationToken)
Loads the specified service.
bool IsResuming
If App is resuming service.
bool BeginUnload()
Sets the IsLoading flag if the service isn't already unloading.
void EndUnload()
Sets the IsLoading and IsLoaded flags and fires an event representing the current load state of the s...
bool IsLoaded
Gets whether the service is loaded.
EventHandler< LoadedEventArgs > Loaded
Fires whenever the loading state of the service changes.
A service that can be loaded and unloaded at will. Typically during startup and shutdown of an applic...