forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuartzThread.cs
138 lines (125 loc) · 3.96 KB
/
QuartzThread.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#region License
/*
* All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#endregion
using System;
using System.Globalization;
using System.Threading;
namespace Quartz
{
/// <summary>
/// This interface should be implemented by any class whose instances are intended
/// to be executed by a thread.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
public interface IThreadRunnable
{
/// <summary>
/// This method has to be implemented in order that starting of the thread causes the object's
/// run method to be called in that separately executing thread.
/// </summary>
void Run();
}
/// <summary>
/// Support class used to handle threads
/// </summary>
/// <author>Marko Lahma (.NET)</author>
public abstract class QuartzThread : IThreadRunnable
{
/// <summary>
/// The instance of System.Threading.Thread
/// </summary>
private readonly Thread thread;
/// <summary>
/// Initializes a new instance of the QuartzThread class
/// </summary>
protected QuartzThread()
{
thread = new Thread(Run);
}
/// <summary>
/// Initializes a new instance of the Thread class.
/// </summary>
/// <param name="name">The name of the thread</param>
protected QuartzThread(string name)
{
thread = new Thread(Run);
Name = name;
}
/// <summary>
/// This method has no functionality unless the method is overridden
/// </summary>
public virtual void Run()
{
}
/// <summary>
/// Causes the operating system to change the state of the current thread instance to ThreadState.Running
/// </summary>
public void Start()
{
thread.Start();
}
/// <summary>
/// Interrupts a thread that is in the WaitSleepJoin thread state
/// </summary>
protected void Interrupt()
{
thread.Interrupt();
}
/// <summary>
/// Gets or sets the name of the thread
/// </summary>
public string Name
{
get { return thread.Name; }
protected set
{
thread.Name = value;
}
}
/// <summary>
/// Gets or sets a value indicating the scheduling priority of a thread
/// </summary>
protected ThreadPriority Priority
{
get { return thread.Priority; }
set { thread.Priority = value; }
}
/// <summary>
/// Gets or sets a value indicating whether or not a thread is a background thread.
/// </summary>
protected bool IsBackground
{
set { thread.IsBackground = value; }
}
/// <summary>
/// Blocks the calling thread until a thread terminates
/// </summary>
public void Join()
{
thread.Join();
}
/// <summary>
/// Obtain a string that represents the current object
/// </summary>
/// <returns>A string that represents the current object</returns>
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "Thread[{0},{1},]", Name, Priority);
}
}
}