我正在使用視頻流式算法。我將整個視頻分成了一系列圖像。現在每個圖像將根據時間進行流式傳輸(Image.TimeInMs
表示圖像流式傳輸或發送的時間)。保持我有System.Timer.Timer
對象的時間。並行運行兩個循環
_timer = new System.Timers.Timer(250);
_timer.Elapsed += new ElapsedEventHandler(timeCounterIncrementer);
_timer.Enabled = true;
for(i =0; i<imageArray.length;i++)
{
while (timeCounter < imageArray[i].TimeInMs)
{
StreamImage();
}
}
void timeCounterIncrementer(object sender, ElapsedEventArgs e)
{
timeCounter+=250;
}
在上面的代碼while循環運行定時器方法timeCounterIncrementer
將不執行時。我希望計時器方法一方面運行而另一方面運行While循環。換句話說,如何並行運行while循環和timer方法?
你可以使用線程並同步腳步嗎? – Roy
我可以使用線程,但無法同步。由於while循環和定時器必須並行執行並且更多地通過其視頻流,因此時間精度是主要要求。定時器的值應該與滑塊的值一致,視頻播放器 –