History

Updated local paths, files names and references to GSF.Code.Shared

J. Ritchie Carroll committed 10 years ago

Commit 0d1cb7f1 parent 719dee6126 files · +10 −76Browse files

Showing the changes to Source/Libraries/GSF.Core.Shared/Threading/ThreadContainerThreadpool.cs (1 of 126 files). Show all

Unified · Split

Source/Libraries/GSF.Core.Shared/Threading/ThreadContainerThreadpool.cs+104−0
@@ -0,0 +1,104 @@
1+//******************************************************************************************************
2+// ThreadContainerThreadpool.cs - Gbtc
3+//
4+// Copyright © 2014, Grid Protection Alliance. All Rights Reserved.
5+//
6+// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
7+// the NOTICE file distributed with this work for additional information regarding copyright ownership.
8+// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may
9+// not use this file except in compliance with the License. You may obtain a copy of the License at:
10+//
11+// http://www.opensource.org/licenses/MIT
12+//
13+// Unless agreed to in writing, the subject software distributed under the License is distributed on an
14+// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
15+// License for the specific language governing permissions and limitations.
16+//
17+// Code Modification History:
18+// ----------------------------------------------------------------------------------------------------
19+// 3/8/2014 - Steven E. Chisholm
20+// Generated original version of source code.
21+//
22+//
23+//******************************************************************************************************
24+
25+using System.Diagnostics.CodeAnalysis;
26+using System.Threading;
27+
28+namespace GSF.Threading
29+{
30+ [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")]
31+ internal class ThreadContainerThreadpool
32+ : ThreadContainerBase
33+ {
34+ /// <summary>
35+ /// Handle that is created when telling the threadpool to do a delayed start.
36+ /// </summary>
37+ private volatile RegisteredWaitHandle m_registeredHandle;
38+
39+ /// <summary>
40+ /// The reset event that allows the timer to be short circuited.
41+ /// </summary>
42+ private ManualResetEvent m_waitObject;
43+
44+ public ThreadContainerThreadpool(WeakAction<CallbackArgs> callback)
45+ : base(callback)
46+ {
47+ m_waitObject = new ManualResetEvent(false);
48+ }
49+
50+ protected override void InternalStart(int delay)
51+ {
52+ m_waitObject.Reset();
53+ m_registeredHandle = ThreadPool.RegisterWaitForSingleObject(m_waitObject, BeginRunOnTimer, null, delay, executeOnlyOnce: true);
54+ }
55+
56+ protected override void InternalStart_FromWorkerThread(int delay)
57+ {
58+ m_waitObject.Reset();
59+ m_registeredHandle = ThreadPool.RegisterWaitForSingleObject(m_waitObject, BeginRunOnTimer, null, delay, executeOnlyOnce: true);
60+ }
61+
62+ private void BeginRunOnTimer(object state, bool isTimeout)
63+ {
64+ //Wait for this race condition to satisfy
65+ while (m_registeredHandle == null)
66+ ;
67+ m_registeredHandle.Unregister(null);
68+ m_registeredHandle = null;
69+ OnRunning();
70+ }
71+
72+ protected override void InternalCancelTimer()
73+ {
74+ m_waitObject.Set();
75+ }
76+
77+ protected override void InternalStart()
78+ {
79+ ThreadPool.QueueUserWorkItem(BeginRunImmediately);
80+ }
81+
82+ protected override void InternalStart_FromWorkerThread()
83+ {
84+ ThreadPool.QueueUserWorkItem(BeginRunImmediately);
85+ }
86+
87+ private void BeginRunImmediately(object state)
88+ {
89+ OnRunning();
90+ }
91+
92+ protected override void InternalDispose_FromWorkerThread()
93+ {
94+ m_waitObject.Dispose();
95+ m_waitObject = null;
96+ }
97+
98+ protected override void InternalDoNothing_FromWorkerThread()
99+ {
100+
101+ }
102+
103+ }
104+}

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