c++ - 如何暂停一个程序几毫秒?

标签 c++

如何使用 C++ 托管代码将程序暂停几毫秒? 我试过 Sleep() 但当我包含 winbase.h 文件时它不起作用,我遇到了很多编译错误!

for(int i=0; i<10; i++)
 {
   simpleOpenGlControl1->MakeCurrent();
  System::Threading::Thread::Sleep(100);
      theta_rotated += 2.0* 3.141592653/(double)Model->size()/10.0;

  simpleOpenGlControl1->Invalidate();
 }

private: System::Void simpleOpenGlControl1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
         {

             Gl::glMatrixMode(Gl::GL_MODELVIEW);
             Gl::glLoadIdentity();
             Gl::glClearColor(1, 1, 1, 1);
             Gl::glClear(Gl::GL_COLOR_BUFFER_BIT | Gl::GL_DEPTH_BUFFER_BIT);
             camera->Tellgl();
             Gl::glRotated(Angle,X,Y,Z);
             RenderModels();
         }
void RenderModels(void)
{
    Points = gcnew System::Collections::Generic::List<Point>();
    Point p(0,0) ;
    int t = -5;
    double r = 5;
    double x, z, theta;
    for(int i = 0;i < Model->size();i++)
    {
        theta = i*2* 3.141592653/ (double)Model->size();
        x = r*sin(theta + theta_rotated);
        z = r*cos(theta + theta_rotated);
         Gl::glPushMatrix();
         Gl::glTranslated(x,0,z);
         Model->at(i).Render();
         p.X=x;
         p.Y=0;

         Points->Add(p);
         t +=1;
         Gl::glPopMatrix();
    }
    //simpleOpenGlControl1->Invalidate();
}

最佳答案

您需要 System::Threading::Thread::Sleep()http://msdn.microsoft.com/en-us/library/system.threading.thread.sleep.aspx

关于c++ - 如何暂停一个程序几毫秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2463982/

相关文章:

c++ - 将 C++ 程序与 Fortran 库链接时对 _rpoly_ 的 undefined reference

c++ - OpenCV - 手骨架节点

c++ - 在结构 vector 的 vector 成员内部搜索

c++ - 在运行 cvCopyImage/cvResize 时崩溃

c++ - 在 Visual Studio 2015 中运行单个 .cpp 文件?

C++双指针成员访问

c++ - 什么时候完整类作用域在默认参数,默认成员初始化程序和异常说明中真正有用?

c++ - 为什么不能 for_each 修改它的仿函数参数?

c++ - 如何在VS2015中添加一些头文件

C++:遍历泛型列表