Class ThreadClass
Support class used to handle threads that is inheritable just like the Thread type in Java. This class also ensures that when an error is thrown on a background thread, it will be properly re-thrown on the calling thread, which is the same behavior as we see in Lucene.
Inheritance
Implements
Inherited Members
Namespace: Lucene.Net.Support.Threading
Assembly: Lucene.Net.dll
Syntax
public class ThreadClass : IThreadRunnable
Constructors
| Improve this Doc View SourceThreadClass()
Initializes a new instance of the ThreadClass class
Declaration
public ThreadClass()
ThreadClass(String)
Initializes a new instance of the Thread class.
Declaration
public ThreadClass(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name of the thread |
ThreadClass(ThreadStart)
Initializes a new instance of the Thread class.
Declaration
public ThreadClass(ThreadStart start)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.ThreadStart | start | A ThreadStart delegate that references the methods to be invoked when this thread begins executing |
ThreadClass(ThreadStart, String)
Initializes a new instance of the Thread class.
Declaration
public ThreadClass(ThreadStart start, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.ThreadStart | start | A ThreadStart delegate that references the methods to be invoked when this thread begins executing |
| System.String | name | The name of the thread |
Properties
| Improve this Doc View SourceInstance
Gets the current thread instance
Declaration
public Thread Instance { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Threading.Thread |
IsAlive
Gets a value indicating the execution status of the current thread
Declaration
public bool IsAlive { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsBackground
Gets or sets a value indicating whether or not a thread is a background thread.
Declaration
public bool IsBackground { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsDebug
If true when Join(), Join(Int64) or Join(Int64, Int32) is called,
any original exception and error message will be wrapped into a new System.Exception when thrown, so
debugging tools will show the correct stack trace information.
NOTE: This changes the original exception type to System.Exception, so this setting should not be used if
control logic depends on the specific exception type being thrown. An alternative way to get the original
System.Exception.ToString() message is to use exception.Data["OriginalMessage"].ToString().
Declaration
public bool IsDebug { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Name
Gets or sets the name of the thread
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
State
Declaration
public ThreadState State { get; }
Property Value
| Type | Description |
|---|---|
| System.Threading.ThreadState |
Methods
| Improve this Doc View SourceCurrent()
Gets the currently running thread
Declaration
public static ThreadClass Current()
Returns
| Type | Description |
|---|---|
| ThreadClass | The currently running thread |
CurrentThread()
Declaration
public static ThreadClass CurrentThread()
Returns
| Type | Description |
|---|---|
| ThreadClass |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Overrides
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
Interrupt()
Interrupts a thread that is in the WaitSleepJoin thread state
Declaration
public virtual void Interrupt()
Join()
Blocks the calling thread until a thread terminates
Declaration
public void Join()
Join(Int64)
Blocks the calling thread until a thread terminates or the specified time elapses
Declaration
public void Join(long milliSeconds)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | milliSeconds | Time of wait in milliseconds |
Join(Int64, Int32)
Blocks the calling thread until a thread terminates or the specified time elapses
Declaration
public void Join(long milliSeconds, int nanoSeconds)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | milliSeconds | Time of wait in milliseconds |
| System.Int32 | nanoSeconds | Time of wait in nanoseconds |
Resume()
Resumes a thread that has been suspended
Declaration
public void Resume()
Run()
This method has no functionality unless the method is overridden
Declaration
public virtual void Run()
SafeRun(ThreadStart)
Safely starts the method passed to start and stores any exception that is
thrown. The first exception will stop execution of the method passed to start
and it will be re-thrown on the calling thread after it calls Join(),
Join(Int64), or Join(Int64, Int32).
Declaration
protected virtual void SafeRun(ThreadStart start)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.ThreadStart | start | A System.Threading.ThreadStart delegate that references the methods to be invoked when this thread begins executing |
SetDaemon(Boolean)
Declaration
public void SetDaemon(bool isDaemon)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | isDaemon |
Sleep(Int64)
Declaration
public static void Sleep(long ms)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | ms |
Start()
Causes the operating system to change the state of the current thread instance to ThreadState.Running
Declaration
public virtual void Start()
Suspend()
Suspends the thread, if the thread is already suspended it has no effect
Declaration
public void Suspend()
ToString()
Obtain a String that represents the current object
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A String that represents the current object |
Overrides
Operators
| Improve this Doc View SourceEquality(ThreadClass, Object)
Declaration
public static bool operator ==(ThreadClass t1, object t2)
Parameters
| Type | Name | Description |
|---|---|---|
| ThreadClass | t1 | |
| System.Object | t2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(ThreadClass, Object)
Declaration
public static bool operator !=(ThreadClass t1, object t2)
Parameters
| Type | Name | Description |
|---|---|---|
| ThreadClass | t1 | |
| System.Object | t2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |