Latest pairCodeSome optimizations have been made. After the test, the results are still good, but the interface will flash. Specifically, the Treeview control will flash, the language is C #, And the IDE is vs2005. After reading some materials and using some basic technologies (such as enabling dual-buffering), I found that the performance was ineffective.
Therefore, the profiler tool is used to find out the bottleneck in the endupdate operation of the interface after each update (this is used to reduce the number of page updates, but this is not ideal because there are many elements in the control ), I guess every update ,. net underlying layer will update and repaint each element, so the speed will be slow, resulting in flickering. However, the use of double buffering should have better results. Looking at the code again, we may find that the update operation is too frequent, which reduces the speed and improves, but still does not work.
Continue online, and finally find a suitable solution. It turns out that the canvas is cleared and re-drawn at the underlying layer each time. This is the main cause of flickering. Therefore, the message sending function operation is reloaded to disable this message. The Code is as follows:
Protected override void wndproc (ref message m)
{
If (M. MSG = 0x0014) // disable background message clearing
Return;
Base. wndproc (ref m );
}
Successful!
Note: Dual-buffering is useful when updates are not frequent and the number of elements in the control is not very large. Once there are too many elements, each update takes a long time. Even if dual buffering is used, the problem still cannot be solved. In my opinion, the ideal method is to disable background message clearing.
Appendix: record of failed attempts
1) Use setstyle
On the Internet, you can use the setstyle function to set the parameters of the control, specifically:
Setstyle (controlstyles. userpaint | controlstyles. allpaintinginwmpaint |
Controlstyles. optimizeddoublebuffer, true );
These three option parameters depend on the former and must coexist; otherwise, they are invalid. This function itself is protected, so you must inherit a control before using it.
This goal is consistent with the preceding solution. It also prevents background clearing and dual buffering. However, you need to use the user rendering option, which is all for user plotting. This requires you to plot all controls by yourself, which is troublesome. Therefore, this method is not completely unavailable, but requires additional work and is not recommended. I am not using it either.
2) use beginupdate and endupdate
These operations have a good effect on scenarios where you need to update controls in batches. For example, a large number of nodes are added in batch during initialization. The disadvantage is that it cannot be updated immediately. Therefore, it is not applicable to scenarios where frequent node updates and immediate display of the interface are required. If you use it and do not disable clearing the interface message, the control will appear to flash continuously, and the content is mostly white-based and almost invisible (depending on the complexity of the video ). Because all interface updates are completed at endupdate, too many operations lead to a long blocking time for endupdate and are cleared first. After the update, the interface looks blank for a long time.
3) Use controlstyles. enablenotifymessage Option
The role of this option is the same as that of the correct solution. The usage is as follows:
Setstyle (controlstyles. enablenotifymessage, true );
Protected override void onnotifymessage (message m)
{
// Write the message filtering code here
}
However, the actual experiment shows no effect. I don't know why, so I didn't go into details.
The Code has been optimized recently. After the test, the results are still good, but the interface will flash. Specifically, the Treeview control will flash, the language is C #, And the IDE is vs2005. After reading some materials and using some basic technologies (such as enabling dual-buffering), I found that the performance was ineffective.
Therefore, the profiler tool is used to find out the bottleneck in the endupdate operation of the interface after each update (this is used to reduce the number of page updates, but this is not ideal because there are many elements in the control ), I guess every update ,. net underlying layer will update and repaint each element, so the speed will be slow, resulting in flickering. However, the use of double buffering should have better results. Looking at the code again, we may find that the update operation is too frequent, which reduces the speed and improves, but still does not work.
Continue online, and finally find a suitable solution. It turns out that the canvas is cleared and re-drawn at the underlying layer each time. This is the main cause of flickering. Therefore, the message sending function operation is reloaded to disable this message. The Code is as follows:
Protected override void wndproc (ref message m)
{
If (M. MSG = 0x0014) // disable background message clearing
Return;
Base. wndproc (ref m );
}
Successful!
Note: Dual-buffering is useful when updates are not frequent and the number of elements in the control is not very large. Once there are too many elements, each update takes a long time. Even if dual buffering is used, the problem still cannot be solved. In my opinion, the ideal method is to disable background message clearing.
Appendix: record of failed attempts
1) Use setstyle
On the Internet, you can use the setstyle function to set the parameters of the control, specifically:
Setstyle (controlstyles. userpaint | controlstyles. allpaintinginwmpaint |
Controlstyles. optimizeddoublebuffer, true );
These three option parameters depend on the former and must coexist; otherwise, they are invalid. This function itself is protected, so you must inherit a control before using it.
This goal is consistent with the preceding solution. It also prevents background clearing and dual buffering. However, you need to use the user rendering option, which is all for user plotting. This requires you to plot all controls by yourself, which is troublesome. Therefore, this method is not completely unavailable, but requires additional work and is not recommended. I am not using it either.
2) use beginupdate and endupdate
These operations have a good effect on scenarios where you need to update controls in batches. For example, a large number of nodes are added in batch during initialization. The disadvantage is that it cannot be updated immediately. Therefore, it is not applicable to scenarios where frequent node updates and immediate display of the interface are required. If you use it and do not disable clearing the interface message, the control will appear to flash continuously, and the content is mostly white-based and almost invisible (depending on the complexity of the video ). Because all interface updates are completed at endupdate, too many operations lead to a long blocking time for endupdate and are cleared first. After the update, the interface looks blank for a long time.
3) Use controlstyles. enablenotifymessage Option
The role of this option is the same as that of the correct solution. The usage is as follows:
Setstyle (controlstyles. enablenotifymessage, true );
Protected override void onnotifymessage (message m)
{
// Write the message filtering code here
}
however, the actual experiment shows no effect. I don't know why, so I didn't go into details.