在winform中嵌入player控件,加载页面的时候初始化播放列表,要求播放MP3文件的时候加以控制(听力考试)
比如:
     播放完第一个文件后暂停3秒中再播放下一个文件,我通过捕获播放器状态的改变事件回调方法,通过线程的sleep方法来暂停线程,实现上面所说的要求,但是这么做出现了一个问题,线程睡眠的时候,winform界面也不可用了,造成了程序假死的现象,各位大牛,能有什么方法解决这个问题吗?或者换一种方式实现上面的需求,急等!!!!!
附代码如下
protected void myPlayer_StatusChange(object sender, EventArgs e)
        {
            int k = (int)myPlayer.playState;
            if (((int)myPlayer.playState == 8) && this.index < 11)
            {
                this.index++;
                if (this.index % 2 != 0)
                {
                    System.Threading.Thread.Sleep(3000);
                    myPlayer.Ctlcontrols.play();
                }
                else
                {
                    System.Threading.Thread.Sleep(11000);
                    myPlayer.Ctlcontrols.play();
                }
            }
        }

解决方案 »

  1.   

    试过了,不能用定时器实现,因为在控件每次打开一个MP3文件需要时间,播放列表里有6个MP3文件,这样时间间隔不好设置,还有别的方法没?
      

  2.   

    在主线程中创建子线程,楼主好像是在主线程中sleep的呢
    说的不对,愿大侠们指点呢
    学习
     学习
      

  3.   

    试试 
      myTimer.Tick += new EventHandler(TimerEventProcessor);
       
    protected void myPlayer_StatusChange(object sender, EventArgs e)
       {
       
       int k = (int)myPlayer.playState;
       if (((int)myPlayer.playState == 8) && this.index < 11)
       {
       this.index++;
       if (this.index % 2 != 0)
       {       // Sets the timer interval to 3 seconds.
           myTimer.Interval = 3000;
           myTimer.Start();      
       }
       else
       {
           // Sets the timer interval to 11 seconds.
           myTimer.Interval = 11000;
           myTimer.Start();      
       }
       }
       }
          
       
       
        // This is the method to run when the timer is raised.
        private static void TimerEventProcessor(Object myObject,
                                                EventArgs myEventArgs) {
           myTimer.Stop();       myPlayer.Ctlcontrols.play();    }