| |

VerySource

 Forgot password?
 Register
Search
Author: aspirinum

About loop waiting

[Copy link]

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-15 12:15:01
| Show all posts
The ones upstairs can't be nested. I'm very surprised. Can I post a nesting example for everyone to learn? ?
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-8-16 16:15:01
| Show all posts
There are definitely nested (and many) in my program, but this happens on a few machines, but some are better after redoing the system, and some are still not working. I guess it may be caused by improper use of DoEvents.
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

 Author| Post time: 2020-8-16 16:30:02
| Show all posts
Part of my code is in "High scores for help: about doevents issues, online etc.!" In the post, it is the code of .net, but there is not much difference. This is also the case in vb6. There is a version that uses multithreading. There is a UI thread and a worker thread. No problems have been found so far. This is an old version of the program and there is no time for major changes. I can only ask the experts to help analyze the possible causes and solutions.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 12:45:01
| Show all posts
sub delay(delaytime)
dim start
start=timer
do while timer<start+delaytime
doevents
loop
end sub
doevents will reduce the efficiency of program execution
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 13:30:01
| Show all posts
I’m really surprised. I have used VB for several years, and I never knew that DoEvents would have problems.

"DoEvents will reduce the efficiency of program execution", my understanding is: "DoEvents is meant to reduce the efficiency of your program execution". What you should know is that in the loop, every time DoEvents is executed, your program will release you CPU control right (of course this is within your privilege level), at this time, your program and the system will check whether there are other places that need the CPU, and the CPU will return to the back of DoEvents after executing other requests The statement continues to execute.

Having said that, if your program is so fragile that DoEvents (instantly in the loop) will affect your performance, the problem is often that your code is not good enough.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 17:15:01
| Show all posts
Ha ha, not necessarily, the cpu is not good enough, the program execution efficiency will be very low. . . Doevents is to get the program out of the idle loop, in a sense, it will make the program healthier.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-18 18:00:02
| Show all posts
1. Waiting for less than 3 seconds, it can be said that there is no response to the user;
2. Wait for 3 to 5 seconds. For the user, it can be tolerated and can be displayed by the mouse (hourglass);
3. Waiting for 5 to 10 seconds is the upper limit for users to tolerate. Information can be displayed through the status bar, mouse status, etc.;
4. Waiting for more than 10 seconds is unbearable for the user. You need to set up an information display window to display it to the user.

Summarize by yourself, and if you have different opinions, you can bring up.
Reply

Use magic Report

1

Threads

21

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-8-18 18:15:01
| Show all posts
I agree with the above statement, I have used the following methods to solve the waiting
1. Mouse hourglass
2. doevents
3. Progress bar or prompt window
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-19 10:15:01
| Show all posts
Doevents are necessary in many cases, if you don't need multithreading. One of your processes has to deal with a large amount of data (a few hundred M to a few G). For example, the fastest computer for copying files is now 5-8M bytes/sec because it must use disks. Generally, computers do not have such a large memory. 500M takes 2 minutes, so users face an hourglass? ? Yes, but the program will generally freeze due to lack of system resources! Various interfaces can't refresh the progress bar nor will there be any changes because your program has no resources available. You can experiment. Add the middle part of the two lines at the beginning of Form_Load to see.
Private Sub Form_Load()
'---------------------------------------------
Dim i As Date
i = Now
i = DateAdd("s", 15, i)'Wait for 15 seconds to see if it is very depressed
Me.Visible = True
Do
     If i <Now Then Exit Do
     'DoEvents
Loop While 1
me.Caption="The cycle is complete"
'----------------------------------------------
'...Other statements
End Sub
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-19 10:30:01
| Show all posts
This should be an example of Doevents nesting. Wait up to 25 seconds and wait patiently
Private Sub Form_Click()
Static ptr As Integer, i As Date
i = Now: ptr = ptr + 1
If ptr> 4 Then Exit Sub
i = DateAdd("s", 5, i)
Me.Print Time
Me.MousePointer = 11
Do
     If i <Now Then Exit Do
     'DoEvents
Loop While 1
Me.Print "End of cycle"
Me.MousePointer = 0
End Sub
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