新手求助,请问在基于formView的单文档程序中,我需要每过段时间对数据进行处理,现在用的方法是,在OnTimer中计算,但是由于需要Sleep,导致界面会卡,现在我想用线程做。 请问怎么用AfxBeginThread创建线程,是在OnTimer中创建吗?

解决方案 »

  1.   

    不必再OnTimer中创建线程,可以加到其他地方。在线程中Sleep()
      

  2.   

    主线程中创建
    线程跟onTimer没关系
      

  3.   

    两种实现:
    1)你在OnTimer里创建线程,就像你说的那样
    2)在formView初始化的地方创建线程,线程里while循环,处理完数据Sleep一段时间,然后再继续。
      

  4.   

    是这样的,我是需要一定时间调用线程中的函数。(本来是做在OnTimer中的) ,如果我不是在定时器中创线程,会实现多少时间调用一次数据处理函数吗? 没用过多线程,不是很懂
      

  5.   

    在OnTimer里SetEvent,线程里wait这个event
      

  6.   

    我能不能这么认为,在view类的OnInitialUpdate(),创建一条线程,然后在线程函数中判断,WHILE线程存在就运行我需要的函数,最后SLEEP(2000),这样就实现了每2S处理的作用。 
      

  7.   

    SetWaitableTimer
    The SetWaitableTimer function activates the specified "waitable" timer. When the due time arrives, the timer is signaled and the thread that set the timer calls the optional completion routine.BOOL SetWaitableTimer(
      HANDLE hTimer,                          // handle to a timer object
      const LARGE_INTEGER *pDueTime,          // when timer will become signaled
      LONG lPeriod,                           // periodic timer interval
      PTIMERAPCROUTINE pfnCompletionRoutine,  // completion routine
      LPVOID lpArgToCompletionRoutine,        // data for completion routine
      BOOL fResume                            // flag for resume state
    );
     
    这个可是定时
      

  8.   

    如果时间要求不严格可以用Sleep
    Sleep误差很大
      

  9.   

    对. 在Ontimer中创建线程不太好, 因为时间还是来不及, 所以应优化代码,缩短程序执行时间. 如不行, 只好改变OnTimer的时间间隔.
      

  10.   

    还有人吗?请问这么创建线程不行吗
    CWinThread *AfxBeginThread=(Thread1,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL); 
    static UINT Thread1();