How to force events inside a recursive function?

I am writing a screensaver in C # that slowly draws the Sierpinski triangle. I use the Thread.Sleepinside recursive function to slow down the drawing. But I need the user to be able to exit by moving the mouse, pressing a key, etc. Since my drawing function is called from within the Paintform's event handler , mouse and keyboard events are only processed after a whole triangle, which may take some time. How to force a form to handle events while a recursive function is running? (And how to avoid the endless loop caused by the call of the drawing event, which calls the drawing function, which forces the event processing to call the drawing event, etc.?)

+3
source share
2 answers

Well, you can use Application.DoEvents- but I'm not sure what I advise. You can easily solve reconnection problems, especially in an event Paint.

It seems that all the real work really needs to be done in the user interface thread, if you are handling the event Paint- is this correct?

Bitmap Paint. , , , , ( - ), , . . Paint - PictureBox, " ". , , .

+4

backbuffer, /, , Paint. .

+2

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


All Articles