using
System
;
using
System
.
Threading
;
namespace
ThreadPollLearn
{
class
Program
{
private
static
void
AsyncOperation
(
object
state)
{
System
.
Console
.
WriteLine
(
$"Operation state:{
state
??
"{null}"}"
);
System
.
Console
.
WriteLine
(
$"Worker thread id:{
Thread
.
CurrentThread
.
ManagedThreadId
}"
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
2
));
}
static
void
Main
(
string
[] args)
{
const
int
x
=
1
;
const
int
y
=
2
;
const
string
lambdaState
=
"lambda ststa 2"
;
ThreadPool
.
QueueUserWorkItem
(
AsyncOperation
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
1
));
ThreadPool
.
QueueUserWorkItem
(
AsyncOperation
,
"Async state"
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
1
));
ThreadPool
.
QueueUserWorkItem
(state
=>
{
System
.
Console
.
WriteLine
(
$"Operation state:{
state
}"
);
System
.
Console
.
WriteLine
(
$"Worker thread id:{
Thread
.
CurrentThread
.
ManagedThreadId
}"
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
2
));
},
"lamda state"
);
ThreadPool
.
QueueUserWorkItem
(_
=>
{
System
.
Console
.
WriteLine
(
$"Operation state:{
x
+
y
}"
);
System
.
Console
.
WriteLine
(
$"Worker thread id:{
Thread
.
CurrentThread
.
ManagedThreadId
}"
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
2
));},
"lamda state"
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
2
));
}
}
}