总体情况是从body {
background-color:#d6d6d6;
}
.container {
position: relative;
margin: 200px auto;
background-color:red;
width:478px;
height:200px;
}
img {
float:left;
width:239px;
height:200px;
}
#facial {
position:absolute;
right: 0;
width:239px;
height:200px;
background-color:#008aaf;
}
#facial h1, #facial h2 {
text-align:center;
margin-top:30px;
color:#FFFFFF;
}
打印Thread t
到某个值,然后暂停执行,具体取决于执行另一个线程1
的{{1}}。 signal (ManualResetEvent)
完成后,s
。因此,s
恢复执行。
sets the signal
程序在前半部分按预期工作,直到T
class A
{
int key;
int temp;
public A(int x)
{
key = x;
}
public EventHandler eventHandler;
private void onKeyReached(object sender, EventArgs e)
{
eventHandler(this, e);
}
public int Temp
{
get { return temp; }
set
{
if (value == temp) return;
else if (temp == key)
onKeyReached(this, EventArgs.Empty);
else
temp = value;
}
}
}
class Test
{
static A a = new A(500);
//signal to pause or resume threads
static ManualResetEvent signal = new ManualResetEvent(true);
static void Main()
{
a.eventHandler += WorkOnKeyReached;
Thread t = new Thread(F);
t.Start();
}
static void F()
{
for (int i = 0; i < 1000; i++)
{
a.Temp = i;
//when a.Temp == a.Key, a.OnkeyReached() is fired.
signal.WaitOne();
Console.WriteLine(a.Temp);
}
}
static void WorkOnKeyReached(object sender, EventArgs e)
{
signal.Reset();
Thread s = new Thread(() =>
{
Console.WriteLine("Doing something else...");
Thread.Sleep(3000);
Console.WriteLine("Done..");
signal.Set();
});
s.Start();
}
}
t
signal
暂停reset
。
在WorkOnKeyReached
完成后,我WorkOnKeyReached
set
期待signal
继续。
输出中:
t
任何人都可以帮助解释这种现象吗?我只是在玩Threads和其他东西。
答案 0 :(得分:0)
public int Temp
{
get { return temp; }
set
{
if (value == temp) return;
else if (temp == key)
onKeyReached(this, EventArgs.Empty);
//else
temp = value;
}
}
基本上取出其他或者永远不会超过500