我编写的程序在运行大量的数据需要等待的时候,程序就会进入未响应阶段,不能够做别的事。直到全部运行完成后,才能做别的事,这是为什么?还请有经验的人不吝赐教!!

解决方案 »

  1.   

    你的程序是单线程的呀,它在运行时会使用所有的CPU资源,其他程序得不到计算时间当然不能工作了
    一般在这样的工作中
    我们会在循环中加入
    doevents
    把控制权交换给操作系统,这样其他任务也能得到资源分配了
      

  2.   

    _beginthread或者CreateThread都行,要例子吗??
      

  3.   

    在运行大量的数据的程序中或大的循环中加入:
    MSG msg;
    while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }当然用多线程也不错。
      

  4.   

    #include "stdafx.h"BOOL flag;
    DWORD WINAPI ThreadProc(void*pParam)
    {
    DWORD cnt=*((DWORD*)pParam);

    DWORD things=0;
    for (DWORD i=0;i<cnt && flag;i++){
    things++;
    }
    return 0;
    }
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    flag=TRUE;
    DWORD b=0x87654321;
    HANDLE x=CreateThread(0,0,ThreadProc,&b,0,0); // Main message loop
    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)) {
    /* Until WM_QUIT message */
    switch(msg.message){
    case WM_QUIT:
    flag=FALSE;
    WaitForSingleObject(x,5000);
    return 0;
    case WM_CLOSE:
    flag=FALSE;
    WaitForSingleObject(x,5000);
    return 0;
    }
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }