加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

SuspendThread()和 ResumeThread()

// one.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
using namespace std;
DWORD WINAPI MyThread(void* p)
{
    for(int i=0;i<100;i++)
    {
        cout<<"hello everyone."<<endl;
        Sleep(100);
        return 0;
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE handle;
    DWORD dw;
    handle = CreateThread(NULL,0,MyThread,NULL,0,&dw);
    Sleep(100);
    for(int i=0;i<10;i++)
    {
        cout<<"now suspended "<<endl;
        SuspendThread(handle);
        for(int j=0;j<3;j++)
        {
            cout<<"good thank you"<<endl;
            Sleep(100);
        }
        cout<<"now sesume"<<endl;
        ResumeThread(handle);
        Sleep(300);
    }
    CloseHandle(handle);
    getchar();
    return 0;
}

posted on 2012-04-23 23:56 加文 阅读(1587) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理