8,735
社区成员
发帖
与我相关
我的任务
分享
Thread thread ;
void Window1_Loaded(object sender, RoutedEventArgs e)
{
thread = new Thread(new ThreadStart(timeTick));
}
private void btnPlay_Click(object sender, RoutedEventArgs e)
{
//播放
if (!thread.IsAlive)
{
try { thread = new Thread(new ThreadStart(timeTick)); }
catch { }
thread.Start();
}
else
{
try
{
thread.Resume();
}
catch { }
}
}
private void btnPause_Click(object sender, RoutedEventArgs e)
{
thread.Suspend();
}
private void btnStop_Click(object sender, RoutedEventArgs e)
{
if (thread.IsAlive)
{
try
{
thread.Resume();
}
catch { }
thread.Abort();
}
}
void timeTick()
{
while (true)
{
Thread mythread = new Thread(() =>
{
if (CommonClass.lstTimeInfo != null && CommonClass.lstTimeInfo.Count != 0)
{
clsTimeInfo clsTimeIndex = null;
int index = CommonClass.currDateTime / mTimeSpan;
if (index < CommonClass.lstTimeInfo.Count)
{
clsTimeIndex = CommonClass.lstTimeInfo[index];
if (clsTimeIndex != null && clsTimeIndex.cmd != null)
{
for (int i = 0; i < CommonClass.lstIPInfos.Count; i++)
{
if (CommonClass.lstIPInfos[i].IsPlay == true)
CommonClass.SendToUdp(clsTimeIndex.cmd, CommonClass.lstIPInfos[i].Ip);
}
}
}
}
});
mythread.Start();
CommonClass.currDateTime = CommonClass.currDateTime + mTimeSpan;
Thread.Sleep(mTimeSpan);
}
}
void timeTick()
{
while (true)
{
if (CommonClass.lstTimeInfo != null && CommonClass.lstTimeInfo.Count != 0)
{
clsTimeInfo clsTimeIndex = null;
int index = CommonClass.currDateTime / mTimeSpan;
if (index < CommonClass.lstTimeInfo.Count)
{
clsTimeIndex = CommonClass.lstTimeInfo[index];
if (clsTimeIndex != null && clsTimeIndex.cmd != null)
{
for (int i = 0; i < CommonClass.lstIPInfos.Count; i++)
{
if (CommonClass.lstIPInfos[i].IsPlay == true)
CommonClass.SendToUdp(clsTimeIndex.cmd, CommonClass.lstIPInfos[i].Ip);
}
}
}
else
{
CommonClass.currDateTime = 0;
this.Dispatcher.Invoke(new Action(() =>
{
try
{
thread.Resume();
}
catch { }
thread.Abort();
}));
}
}
CommonClass.currDateTime = CommonClass.currDateTime + mTimeSpan;
Thread.Sleep(mTimeSpan);
}
}