History

GSF.TimeSeries: Updated ServiceHostBase to call InitiateSafeShutdown. GSF.Threading: Updated call handling to IntiateSafeShutdown. GSF.Core.SqlClr: Added compile time directive for SQLCLR to exclude code as needed from shared code.

J. Ritchie Carroll committed 9 years ago

Commit 9a203f51 parent d4004f54 files · +27 −20Browse files

Unified · Split

4 files
  1. Source/Libraries/GSF.Core.Shared/Threading/ShutdownHandler.cs +20 −17
  2. Source/Libraries/GSF.TimeSeries/ServiceHostBase.cs +4 −0
  3. Source/Libraries/SqlClr/GSF.Core.SqlClr/GSF.Core.SqlClr.csproj +2 −2
  4. Source/Tools/LogFileViewer/Program.cs +1 −1
Source/Libraries/GSF.Core.Shared/Threading/ShutdownHandler.cs+20−17
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 using System;
2525 using System.Collections.Generic;
26+using System.ComponentModel;
2627 using GSF.Collections;
2728 using GSF.Diagnostics;
2829
@@ -60,15 +61,16 @@ namespace GSF.Threading · 31 unmodified lines
6061 /// Gets if this process is shutting down.
6162 /// </summary>
6263 public static bool IsShuttingDown { get; private set; }
64+
6365 /// <summary>
6466 /// Gets if this process has already shut down.
6567 /// </summary>
6668 public static bool HasShutdown { get; private set; }
6769
68− private static List<WeakAction> s_onShutdownCallbackFirst;
69− private static List<WeakAction> s_onShutdownCallbackDefault;
70− private static List<WeakAction> s_onShutdownCallbackLast;
71− private static object s_syncRoot;
70+ private static readonly List<WeakAction> s_onShutdownCallbackFirst;
71+ private static readonly List<WeakAction> s_onShutdownCallbackDefault;
72+ private static readonly List<WeakAction> s_onShutdownCallbackLast;
73+ private static readonly object s_syncRoot;
7274
7375 static ShutdownHandler()
7476 {
@@ -128,6 +130,7 @@ namespace GSF.Threading · 53 unmodified lines
128130
129131 list.RemoveWhere(x => !x.IsAlive);
130132 list.Add(new WeakAction(callback));
133+
131134 return true;
132135 }
133136 }
@@ -135,19 +138,19 @@ namespace GSF.Threading · 1 unmodified line
135138 private static void InitiateSafeShutdown(object sender, EventArgs e)
136139 {
137140 List<WeakAction> shutdownList = new List<WeakAction>();
141+
138142 lock (s_syncRoot)
139143 {
140144 if (IsShuttingDown)
141− {
142145 return;
143− }
146+
144147 IsShuttingDown = true;
145148 shutdownList.AddRange(s_onShutdownCallbackFirst);
146149 shutdownList.AddRange(s_onShutdownCallbackDefault);
147150 shutdownList.AddRange(s_onShutdownCallbackLast);
148151 }
149152
150− foreach (var weakAction in shutdownList)
153+ foreach (WeakAction weakAction in shutdownList)
151154 {
152155 try
153156 {
@@ -160,22 +163,22 @@ namespace GSF.Threading · 6 unmodified lines
160163 }
161164
162165 Logger.Shutdown();
166+
163167 HasShutdown = true;
164168 }
165169
166170 /// <summary>
167− /// Requests that certain components initiate a safe shutdown. This method
168− /// should only be called when the main thread exits. Calling this outside
169− /// of the application exiting could result in unpredictable behavior.
171+ /// Requests that certain components initiate a safe shutdown.
170172 /// </summary>
171− /// <param name="areYouSure">To ensure proper use, specify this value as a constant. 'OnlyCallThisWhenMainExits'</param>
172− public static void InitiateSafeShutdown(string areYouSure)
173+ /// <remarks>
174+ /// This method should only be called when the main thread exits. Calling this outside
175+ /// of the application exiting could result in unpredictable behavior.
176+ /// </remarks>
177+#if !SQLCLR
178+ [EditorBrowsable(EditorBrowsableState.Advanced)]
179+#endif
180+ public static void InitiateSafeShutdown()
173181 {
174− if (areYouSure != "OnlyCallThisWhenMainExits")
175− {
176− throw new InvalidOperationException("This method must only be called when the main thread exits.");
177− }
178−
179182 InitiateSafeShutdown(null, null);
180183 }
181184 }
Source/Libraries/GSF.TimeSeries/ServiceHostBase.cs+4−0
@@ -296,6 +296,8 @@ namespace GSF.TimeSeries · 295 unmodified lines
296296 /// </remarks>
297297 protected virtual void ServiceStartingHandler(object sender, EventArgs<string[]> e)
298298 {
299+ ShutdownHandler.Initialize();
300+
299301 // Define a run-time log
300302 m_runTimeLog = new RunTimeLog();
301303 m_runTimeLog.FileName = "RunTimeLog.txt";
@@ -696,6 +698,8 @@ namespace GSF.TimeSeries · 394 unmodified lines
696698
697699 // Detach from handler for unobserved task exceptions
698700 TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
701+
702+ ShutdownHandler.InitiateSafeShutdown();
699703 }
700704
701705 private void UpdatedStatusHandler(object sender, EventArgs<Guid, string, UpdateType> e)
Source/Libraries/SqlClr/GSF.Core.SqlClr/GSF.Core.SqlClr.csproj+2−2
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 <DebugType>full</DebugType>
1818 <Optimize>false</Optimize>
1919 <OutputPath>..\..\..\..\Build\Output\Debug\Libraries\SqlClr\</OutputPath>
20− <DefineConstants>DEBUG;TRACE</DefineConstants>
20+ <DefineConstants>TRACE;DEBUG;SQLCLR</DefineConstants>
2121 <ErrorReport>prompt</ErrorReport>
2222 <WarningLevel>4</WarningLevel>
2323 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -26,7 +26,7 @@ · 2 unmodified lines
2626 <DebugType>pdbonly</DebugType>
2727 <Optimize>true</Optimize>
2828 <OutputPath>..\..\..\..\Build\Output\Release\Libraries\SqlClr\</OutputPath>
29− <DefineConstants>TRACE</DefineConstants>
29+ <DefineConstants>TRACE;SQLCLR</DefineConstants>
3030 <ErrorReport>prompt</ErrorReport>
3131 <WarningLevel>4</WarningLevel>
3232 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Source/Tools/LogFileViewer/Program.cs+1−1
@@ -44,7 +44,7 @@ namespace LogFileViewer · 43 unmodified lines
4444 }
4545 finally
4646 {
47− ShutdownHandler.InitiateSafeShutdown("OnlyCallThisWhenMainExits");
47+ ShutdownHandler.InitiateSafeShutdown();
4848 }
4949 }
5050 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t