The Thread represents a background thread.
sealed class
|
Thread
|
extends
|
Disposable
|
||
implements
|
INativeHandle
|
This class is platform and framework independent. In order to create a background thread, the IThreadMain interface must be implemented and an instance must be passed to the Start method.
The argument object to pass to the thread main method.
public
property
|
Argument
{
get
set
}
|
||
type
|
object
|
||
value
|
The argument object. |
See also:
IThreadMain.RunThe
error
info
of
the
exception
that
has
occurred
in
the
Run
method
of
the
threads
main
method
(see
IThreadMain).
public
property
|
Error
{
get
}
|
||
type
|
TinmanError
|
||
value
|
The
TinmanError
object
or
null . |
Returns if this thread is running.
public
property
|
IsAlive
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
thread
is
running,
false
if
it
is
not. |
Returns the lifecycle state of this object.
public
virtual
property
|
LifecycleState
{
get
}
|
||
type
|
LifecycleState
|
||
value
|
The lifecycle state. | ||
inherited
|
Disposable.LifecycleState
|
Output a log message when the thread terminates due to an unhandled exception?
public
property
|
LogOnError
{
get
set
}
|
||
type
|
bool
|
||
value
|
true
to
output
a
log
message,
false
to
fail
silently
(i.e.
the
owning
code
is
responsible
for
error
processing,
see
Error).
|
Remarks:
Defaults
to
true
.
The thread name.
public
property
|
Name
{
get
set
}
|
||
type
|
string
|
||
value
|
|
The thread name. |
Returns the raw handle value of the native resource that is contained in this object.
public
property
|
NativeHandle
{
get
}
|
||
type
|
IntPtr
|
||
value
|
The raw handle value. | ||
implements
|
INativeHandle.NativeHandle
|
Remarks:
The documentation of the implementing class will contain information on how to interpret the raw handle value.
Gets or sets the thread priority.
public
property
|
Priority
{
get
set
}
|
||
type
|
ThreadPriority
|
||
value
|
The thread priority. |
Remarks:
The default value is Normal.
Gets or sets the thread main method.
[OwnerValue]
|
||||
public
property
|
ThreadMain
{
get
set
}
|
|||
type
|
IThreadMain
|
|||
value
|
|
The thread main method. |
Creates a new instance of Thread.
public
constructor
|
Thread
()
|
Acquires a strong reference to this disposable object.
[OwnerReturn, ThreadSafe]
|
||||
public
method
|
AcquireTry
()
|
|||
type
|
IDisposable
|
|||
returns
|
this
if
a
new
strong
reference
has
been
acquired,
null
if
this
object
is
already
being
disposed.
|
|||
inherited
|
Disposable.AcquireTry
|
Remarks:
The object will not be actually disposed by calls to Dispose when there is at least one strong reference left. Code that calls the AcquireTry method is responsible for calling the Dispose method accordingly.
This method is not intended to be used in performance-critical code. It should only be used to high-level resource management.
Creates a background thread.
[OwnerReturn]
|
||||
public
static
method
|
Create
(string name,
[Owner]
IThreadMain main,
object parameter = null,
ThreadPriority priority = ThreadPriority.Normal)
|
|||
type
|
Thread
|
|||
params
|
name
|
Name of the background thread. | ||
main
|
[not-null]
|
The thread main method. | ||
parameter
|
Optional parameter to pass to thread main method. | |||
priority
|
The thread priority. | |||
returns
|
|
The running Thread object. |
Remarks:
The new thread is initially suspended and must be started with Start.
Releases all resources held by this object if there are no more strong references to it, decrements the reference counter by one otherwise.
[Dispose, OwnerThis, ThreadSafe]
|
||||
public
method
|
Dispose
()
|
|||
inherited
|
Disposable.Dispose
|
Remarks:
The Dispose method silently returns if the object has already been disposed.
Calls Stop on each of the given threads and then disposes them.
[Dispose]
|
||||
public
static
method
|
DisposeAll
([Owner]
IEnumerable<Thread> threads)
|
|||
params
|
threads
|
[not-null]
|
The threads. |
Waits until this threads has terminated.
public
method
|
Join
(bool wait = true)
|
||
type
|
bool
|
||
params
|
wait
|
Wait for thread to terminate? | |
returns
|
true
if
the
thread
has
terminated,
false
if
it
is
still
running
(can
only
happen
if
wait
is
false ).
|
Remarks:
If the thread has already been terminated, the method returns silently.
Suspends the calling thread for the given amount of time.
public
static
method
|
Sleep
(int32 milliSeconds = 0)
|
||
params
|
milliSeconds
|
[>=0]
|
The
number
of
milliseconds
to
sleep.
Defaults
to
0 .
|
Starts this thread.
public
method
|
Start
()
|
Remarks:
The
method
creates
a
new
background
thread
which
will
execute
the
Run
method
of
the
given
IThreadMain
object
(see
ThreadMain
property).
If the thread has already been started, the method silently returns.
Stops the thread.
public
method
|
Stop
()
|
Remarks:
The thread will be signalled to stop. It will not have been terminated when this method returns. Use the Join method for waiting for the termination of the thread.
If the thread has already been stopped, the method returns silently.
The logger object of this class.
public
static
readonly
field
|
Logger
|
||
type
|
ILogger
|