History

Converted TFS repository to Git.

StephenCWills committed 11 years ago

Commit dd143d71 parent ab7f4b62684 files · +766031 −765809Browse files

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

Unified · Split

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