How to pause the program for a few milliseconds?

How to pause a program for a few milliseconds using managed C ++ code? I tried Sleep (), but it did not work, when I included the winbase.h file, I had a lot of compilation errors!

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(); pX=x; pY=0; Points->Add(p); t +=1; Gl::glPopMatrix(); } //simpleOpenGlControl1->Invalidate(); } 
+4
source share
3 answers

System::Threading::Thread::Sleep() as indicated in another answer. But let me warn you, this is not accurate, and for small (milliseconds) Sleep is extremely inaccurate. that your application works along with other applications and threads, and all of them want CPU time.

+3
source
+4
source
 #include <unistd.h> main() { usleep(2000); // 2 msecs } 

Read the manual pages ;-) male 3 usleep

-2
source

Source: https://habr.com/ru/post/1304380/


All Articles