| |

VerySource

 Forgot password?
 Register
Search
View: 909|Reply: 7

Schedule a task

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-1 23:30:01
| Show all posts |Read mode
Now open a thread under a common class, as follows:
void CTest :: testFunc ()
{
    while (flag == TRUE)
    {
           if (there are images in the buffer)
                Display the image;

           Sleep (100);
    }

}

problem:
1. In this way, it is possible to display an image every 100ms (of course, there must be an image in the buffer at this time). I wonder if this can achieve a timing display function? Is this different from using a timer? Will it receive interference from other threads?

2. If there is no image in the buffer when it is ready to be displayed, it will definitely not be displayed at this time. You must wait another 100ms before coming over to check the display. But it is very likely that there is an image in the buffer 10ms after the condition is judged, so that the image display is not real-time. I wonder if there is any solution to this?


Thank you all! !! !!
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-14 16:00:01
| Show all posts
1. What flag is flag?
2. Is testFunc () executed non-stop? Otherwise, what happens if flag = false exits? So this period cannot be displayed regularly, its display is restricted by flags, etc. Only when they are satisfied, can 100ms be considered The timer does not have the above problem.
3. It is best to control the start of drawing through the flag bit of the buffer
personal opinion for reference only:)
Reply

Use magic Report

0

Threads

55

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-5-15 01:45:01
| Show all posts
Events should be used to drive the display image.
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-16 06:45:02
| Show all posts
while (flag == TRUE)
    {
           if (there is an image in the buffer)
             {
                Display the image;
                Sleep (100);
              }
    }
Can solve the second problem
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-5-16 10:30:01
| Show all posts
The difference between sleep and Timer is that Sleep is stuffed, while Timer does not.

You can use the timer to check every second, if there is data to draw immediately.
Reply

Use magic Report

0

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 United States

Post time: 2020-5-17 14:15:01
| Show all posts
It ’s better to use the message, you must know if there is any image, and then send a message to OnDraw
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-30 12:45:01
| Show all posts
Then sleep (1)
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-6-15 14:45:01
| Show all posts
Should be likersq666said

Use Event to achieve

CreateEvent(...) creates an event object and uses SetEvent(...) to wake you up when the image arrives
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list