foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
{
makeSelfMoves = replay[item.Key];
codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
PrintPieces(codeFile.PieceState());
// MessageBox.Show("rowStart: " + makeSelfMoves[0] + ". rowEnd: " + makeSelfMoves[2] + ". columnStart: " + makeSelfMoves[1] + ". columnEnd: " + makeSelfMoves[3] + "____a is: " + a);
}
我想執行這整個迭代,我負責遊戲重播,以1秒爲間隔。我在我的表格中放置了一個計時器,並將其設置爲1秒(這應該使得片段以1秒的間隔移動)。我做了一個事件,並在循環之前,我把語句,timer1.enabled = true。迭代將以快速方式結束。如何使用定時器設置迭代以使用定時器執行每秒?定時器在winform中迭代
public void ReplayGame()
{
Class2.replayIsOn = true;
replay=serializeMeh.giveBackDictionary();
int[] makeSelfMoves=new int[4];
//Timer t = new Timer();
//t.Interval = 1000;
//t.Tick += timer1_Tick;
//t.Enabled = true;
//t.Start();
if (backgroundWorker1.IsBusy != true)
{
// Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync();
}
//foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
//{
// makeSelfMoves = replay[item.Key];
// codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
// PrintPieces(codeFile.PieceState());
// MessageBox.Show("rowStart: " + makeSelfMoves[0] + ". rowEnd: " + makeSelfMoves[2] + ". columnStart: " + makeSelfMoves[1] + ". columnEnd: " + makeSelfMoves[3]);
//}
}
如果我想重播上述方法被激活。
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
int[] makeSelfMoves = new int[4];
foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
{
makeSelfMoves = replay[item.Key];// delivers an array of a single move location startrow,startcolumn,endrow,endcolun
codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
PrintPieces(codeFile.PieceState());// prints the code on the board
System.Threading.Thread.Sleep(1000);
}
}
它做的工作,但我有問題是循環結束後,就存在消失的作品。是因爲背景工作者,沒有它的原因,我沒有在工作結束時消失。第二次,我激活該方法,它發生
目前還不清楚你想要做什麼。請寫更多。 – Morten 2011-03-21 09:46:33