当有多个线程控制的时钟同时到达时...它会同时出现多个窗体...我想要它先后出现...该怎么办啊.加了这个lock也无济于事...请好心人帮忙看一下...问题在什么地方... public class ThreadOperate
{
private System.Timers.Timer[] timerClock; private int[] totalThreadSeconds; private int[] addClockTimer; //private Thread myThreadItem; private DateTime[] dtPreviousTime; private DateTime[] dtNextTime; private string[] myTitleAlarm; private string[] myTableName; private Thread[] myThreadItem; private int[] dataID; private int jCrea; private int perCount; //用构造函数初始化各个局部变量
public ThreadOperate(int ThreadCount)
{
this.perCount = ThreadCount; myThreadItem = new Thread[ThreadCount]; timerClock = new System.Timers.Timer[ThreadCount]; totalThreadSeconds = new int[ThreadCount]; addClockTimer = new int[ThreadCount]; myTitleAlarm = new string[ThreadCount]; myTableName = new string[ThreadCount]; dataID = new int[ThreadCount]; dtPreviousTime = new DateTime[ThreadCount]; dtNextTime = new DateTime[ThreadCount]; Alarm.AlarmRemindClass.AlarmStruct.execAlarm = new int[ThreadCount]; this.jCrea = 0; } //开始线程
public void StartTest(Alarm.AlarmRemindClass.AlarmStruct[] structAlarm)
{
for(int iCrea=0;iCrea<=Alarm.AlarmRemindClass.AlarmStruct.threadCount-1;iCrea++)
{
totalThreadSeconds[iCrea] = structAlarm[iCrea].totalSeconds; dataID[iCrea] = structAlarm[iCrea].remindID; myTitleAlarm[iCrea] = structAlarm[iCrea].remindTitle; myTableName[iCrea] = structAlarm[iCrea].remindTableName; dtPreviousTime[iCrea] = structAlarm[iCrea].remindPreviousDateTime; dtNextTime[iCrea] = structAlarm[iCrea].remindNextDateTime; Alarm.AlarmRemindClass.AlarmStruct.execAlarm[iCrea] = 0; myThreadItem[iCrea] = new Thread(new ThreadStart(InitializeTimer)); Application.DoEvents(); Thread.Sleep(1000); myThreadItem[iCrea].IsBackground = true;
myThreadItem[iCrea].Name = myTitleAlarm[iCrea].ToString();
myThreadItem[iCrea].Start();
}
} //初始化各个时钟控件
private void InitializeTimer()
{
this.timerClock[this.jCrea] = new System.Timers.Timer();
this.timerClock[this.jCrea].Elapsed += new ElapsedEventHandler(OnTimer);
this.timerClock[this.jCrea].Interval = 1000;
this.addClockTimer[this.jCrea] = 0;
this.timerClock[this.jCrea].Enabled = true;
this.jCrea++;
}        public void ComponseDispose()
        {
            for(int jCrea=0;jCrea<=Alarm.AlarmRemindClass.AlarmStruct.threadCount-1;jCrea++)
            {
                this.timerClock[jCrea].Enabled = false;
                this.timerClock[jCrea].Dispose();
            }
            GC.SuppressFinalize(this);
        } //时钟控件触发事件
private void OnTimer(Object source, ElapsedEventArgs e)
{
for(int jCrea=0;jCrea<=Alarm.AlarmRemindClass.AlarmStruct.threadCount-1;jCrea++)
{
this.addClockTimer[jCrea]++; //若此时已经超过报警时间限制,则自动终止当前线程,释放当前时钟.
if ( !((this.dtPreviousTime[jCrea] <= DateTime.Now) && (DateTime.Now <= this.dtNextTime[jCrea])))
{

continue;
} //若此时钟已经终止,则进行下一轮判断
if ( myTitleAlarm[jCrea] == null )
{
continue;
} //若已经点出了知道了按钮,则将当前时钟控件设置为不可用.将其释放
if ( Alarm.AlarmRemindClass.AlarmStruct.execAlarm[jCrea] == 1 )
{
this.timerClock[jCrea].Enabled = false;
this.timerClock[jCrea].Close();
this.timerClock[jCrea].Dispose();
continue;
} //若到达报警时间.则自动开启窗体,显示报警提示
if ( addClockTimer[jCrea] == totalThreadSeconds[jCrea] )
{
//开始报警;
this.addClockTimer[jCrea] = 0;//关键在此处...当有多个线程控制的时钟同时到达时...它会同时出现多个窗体...我想要它先后出现...该怎么办啊.加了这个lock也无济于事...请好心人帮忙看一下...
 
                    lock(this)
                    {                        frmAlarm reBoundfrm = new frmAlarm(myTableName[jCrea], this.myTitleAlarm[jCrea], dtNextTime[jCrea], dataID[jCrea], jCrea);                        Application.DoEvents();                        reBoundfrm.ShowDialog();                        reBoundfrm.Close();
                    }
} } }
}