[問題] 有關Thread的問題...
class g
{
public static int p[] = new int[n]
public static int px[] = new int[n]
}
//如果我有兩個函式他們 各會創造出矩陣
public void first()
{
for(int i = 0;i<6;i++)
{
//內容
}
}
}
public void second()
{
for(int i = 6;i>0;i--)
{
//內容
}
}
//分別是
p[1]=-1 p[2]=1 p[3]=2 p[4]=-1 p[5]= -1 p[6]=3
px[1]=2 px[2]=3 px[3]=6 px[4]=-1 px[5]= -1 px[6]=-1
//我想要在同時運算並且利用 p[3]=2 ,px[2]=3,在那兩個函式運行到一半的時候就會停
止。
//因為我要平行運算所以要使用Thread
//那我現在用一個按鍵觸發
private void button1_Click(object sender, EventArgs e)
{
Thread thread1=new Thread(first);
thread1.Start(); //因為想說要同時跑所以用thread可以在first()還沒跑完就接著跑
second();
for(nit i = 0 ; i<6 ;i++)
{
if(g.p[g.px[i]]=i)
{
//用此內容來停止函式
MessageBox.Show("END");
}
}
可是以上跑不出來 ,我是想要first和second一起跑,因為不斷檢查p[]和px[]的關係,
所以兩個函式沒跑完就可以停止跳出來,請問一下我這樣是哪裡有問題???
不好意思我是新手= ="",請多多包涵...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.184.189.108
推
12/20 20:43, , 1F
12/20 20:43, 1F