How to increase visual raster/refresh update?
I draw your attention to this screen record video. It says all. Only in maximizing the form not only it takes too long to perform but it almost crashes.
In continuation of the words of friends here, Crowded WinForm environments will cause graphical flickering, some sort of raster-ing/rendering refresh which looks like that video. How can we overcome this matter?
What I've tried:
Code:
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
CreateParams = MyBase.CreateParams
CreateParams.ExStyle = CreateParams.ExStyle Or &H2000000
Return CreateParams
End Get
End Property
Also attaching these on form_load (which are the same I suppose):
Code:
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Code:
MyBase.DoubleBuffered = True
Also DoubleBuffer = True on UserControl itself.
It should be noted that all auto-adding controls are dock=fill (In case of consuming more time to perform) and the UserControl filled with some random controls with also dock=fill.
Is it even a double buffer problem? To be or not to be, "True"?
Extra question: The app startup time is also slow. It is a light project why is it like this? Core-i7 8GB RAM and Windows 11, Could it be VS problem?
Re: How to increase visual raster/refresh update?
No bumping allowed I'm afraid. Your thread is not more important than anyone else's.
Re: How to increase visual raster/refresh update?
I immediately regreted my decision. Just worried about time and day a thread be made, turned out I was wrong.
About "loading forms and controls faster", I found this thread (still reading, it's huge.) here on VBForums but I'm on reply #7, suspected what he meant by "loading" is restoring previous saved values/strings/states.
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
jmcilhinney
Your thread
"Your" not "You're"......come on man, you're triggering my OCD over here :D :lol:
Quote:
Originally Posted by
pourkascheff
What exactly am I looking at here? What are all those boxes that are laid out in a grid on the Form? Are they some kind of Usercontrol? What do they contain? I can see at least 2 labels and what looks like a progress bar.
Are they made at runtime or on the designer?
Need more info here.
Re: How to increase visual raster/refresh update?
Edit:
Didn't aware of how effective Sub New and SuspendLayout are. If you have exact same problem you should give them a try but in my case, No [measurable] changes have been observed.
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
Niya
"Your" not "You're"......come on man, you're triggering my OCD over here :D :lol:
I don't know what your talking about. If you look back at my post and you'res, they both show that I was correct and there's clearly no evidence that that wasn't always the case. ;) Unlike a couple of other forums I moderate at, there doesn't seem to be an "Edit silently" option here, darn it!
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
jmcilhinney
Unlike a couple of other forums I moderate at, there doesn't seem to be an "Edit silently" option here, darn it!
Haha. Even if there were, you've provided me with new evidence:-
Quote:
Originally Posted by
jmcilhinney
I don't know what your talking about.
You did it again :lol: Now it's supposed to be "you're" :D
Also, we do have an edit silently, you just have to make the edit within the first minute....I edited this post twice now.
Quote:
Originally Posted by
pourkascheff
Edit:
Didn't aware of how effective
Sub New and
SuspendLayout are. If you have exact same problem you should give them a try but in my case, No [measurable] changes have been observed.
Are you satisfied?
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
Niya
Are they some kind of Usercontrol? What do they contain? I can see at least 2 labels and what looks like a progress bar.
Yes, they are. A usercontrol containing a 2x2 TableLayoutPanel which lower 2 cells also contain two 2 and as I mentioned on starting post, they filled with some random controls with also dock = fill which are 2 labels, a progressbar, a listbox, a button and few more.
Quote:
Originally Posted by
Niya
Are they made at runtime or on the designer?
Form_Load event consists:
Code:
Private Sub Form1_Load()
Me.SuspendLayout()
TableLayoutPanel1.Controls.Clear()
TableLayoutPanel1.RowCount = 99 'CAN BE GIVEN FROM A CTRL
TableLayoutPanel1.ColumnCount = 99 'CAN BE GIVEN FROM A CTRL
For i = 0 To 99
For j = 0 To 99
TableLayoutPanel1.Controls.Add(New UserControl1 With {.UCDoubleBuffered = True, .Margin = New Padding(0, 0, 0, 0), .Dock = DockStyle.Fill}, CInt(j), CInt(i))
Next
Next
Me.ResumeLayout()
End Sub
Therefore, A 10x10 matrix should be generated programmatically.
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
pourkascheff
Yes, they are. A usercontrol containing a 2x2 TableLayoutPanel which lower 2 cells also contain two 2 and as I mentioned on starting post, they
filled with some random controls with also dock = fill which are 2 labels, a progressbar, a listbox, a button and few more.
Form_Load event consists:
Code:
Private Sub Form1_Load()
Me.SuspendLayout()
TableLayoutPanel1.Controls.Clear()
TableLayoutPanel1.RowCount = 99 'CAN BE GIVEN FROM A CTRL
TableLayoutPanel1.ColumnCount = 99 'CAN BE GIVEN FROM A CTRL
For i = 0 To 99
For j = 0 To 99
TableLayoutPanel1.Controls.Add(New UserControl1 With {.UCDoubleBuffered = True, .Margin = New Padding(0, 0, 0, 0), .Dock = DockStyle.Fill}, CInt(j), CInt(i))
Next
Next
Me.ResumeLayout()
End Sub
Therefore, A 10x10 matrix should be generated programmatically and based on what I've seen around
Oh that's definitely going to cause problems.
Did SuspendLayout give you performance you could live with?
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
Niya
Are you satisfied?
I'm afraid, No. I said "in my case, No [measurable] changes have been observed" right after saying I used them. Plus "New" is used when you are calling a sort of editing window as I'm aware, my form environment can be changing once a while (By command of user) when it is still opening.
Re: How to increase visual raster/refresh update?
Well I'm afraid I have some bad news, Windows controls aren't designed to be used like that. Every Windows control has a handle, a device context as well as numerous other plumping fixtures like message handlers. .Net also adds a lot of extra plumbing to make them work in WinForms the way they do. A .Net Control is far too heavy to be used the way you're trying to use them.
Re: How to increase visual raster/refresh update?
:( I see. You are meaning the hidden magic engine which glues everything together in lowest level, right? Can we get rid of it in WPF or are we talking about a Windows (Not Windows-Form) failure? Cause based on what I've seen around (on the internet and have encountered in industrial instrumentation purposes) it should be happen pretty darn quick. A sort of visually detailed as-large-as-possible-on-screen which operator can show/hide specific groups.
Even a Global-Left-To-Right function (Which isn't even a function. I just wrote Me.RightToLeft = Windows.Forms.RightToLeft.Yes) consumes a time equal to me making tea. Imagine client console meets the lowest specifications possible.
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
pourkascheff
:( I see. You are meaning the hidden magic engine which glues everything together in lowest level, right?
Yes.
Quote:
Originally Posted by
pourkascheff
Can we get rid of it in WPF
WPF doesn't use Windows controls. WPF applications only create one HWND per top level Window. Everything is rendered from a graph of visual objects that are hierarchically related to each other via DirectX. This means WPF could probably do what you're trying to do because of these design choices. I've never stress tested it's engine like that so I can't say for sure. Would you like me to test it?
Re: How to increase visual raster/refresh update?
Quote:
Originally Posted by
pourkascheff
:( I see. You are meaning the hidden magic engine which glues everything together in lowest level, right? Can we get rid of it in WPF or are we talking about a Windows (Not Windows-Form) failure? Cause based on what I've seen around (on the internet and have encountered in industrial instrumentation purposes) it should be happen pretty darn quick. A sort of visually detailed as-large-as-possible-on-screen which operator can show/hide specific groups.
Even a Global-Left-To-Right function (Which isn't even a function. I just wrote Me.RightToLeft = Windows.Forms.RightToLeft.Yes) consumes a time equal to me making tea. Imagine client console meets the lowest specifications possible.
WPF handles things in a completely different way to WinForms, there is a good chance it would fix the performance issues but it would require a major rewrite of all your UI code.
Windows is always going to have issues rendering hundreds of controls like that, this is especially true if there is additional logic going on behind every user control creation.
Might help if you explained what you are tring to achieve as an end result, there may be a better approach instead of the one you are attempting.
Re: How to increase visual raster/refresh update?
Oh,
App startup (Controls being created) happens significantly fast, As you may already noticed from the video. Is it because I wrote LayoutSuspend/LayoutResume in Form_Load event? And what I perform to show you its loss is "Maximizing".
For this matter I found following Form events (Didn't used them before) this way: Is it programmatically sane? I mean are people doing it out there?
Code:
Private Sub Form2_ResizeBegin(sender As Object, e As EventArgs) Handles Me.ResizeBegin
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
MyBase.DoubleBuffered = True
Me.SuspendLayout()
End Sub
Private Sub Form2_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
Me.ResumeLayout()
End Sub
Results: Well, They flicker/refresh/dance whatever-you-call-them time, shortened down to 17.24 seconds. (It is 3.3 times faster than video) I guess it is a relative victory for now but I won't close the thread for a day or two.
Edit:
- Not using resize event because it looks silly. I didn't even try it. Think about it. You suspend something, immediately you resume it in next following line.
- And regarding to previous paragraph, We should use events which starts somewhere and ends somewhere else. Consider you write in LostFocus or GetFocus. App reacts like suspend/resume is bypassed don't you agree? I am looking in TLP events. They would be helpful, but since it doesn't have ResizeBegin and ResizeEnd events it's a bit tricky to implement and make app to understand be suspend until you finish resizing, docking and stuffs, then resume.
Re: How to increase visual raster/refresh update?
The flickering and dancing is all symptoms of tearing. Windows controls go through a lot of steps for painting, and that painting happens in a hierarchy. And, just to trigger Niya, youse gonna have to do something different. Y'all might consider WPF, but that would mean fundamentally re-creating the UI. It would essentially mean starting over, and you shouldn't see it as much less than that.
When a control becomes dirty, which can happen when something moves over it, or it changes size, or changes content, or pretty much anything else that alters how it gets displayed, then the control gets a paint event. The first step of that is to clear the pixels that the control occupies to white, then draw in the new control. Your screen has a refresh speed, which is the speed that the image is drawn to the screen. Normally, the 'clear to white' and the redraw, take place in less than one refresh. The white image never gets drawn to the screen because it is replaced with the new image before the white image has a chance to draw. However, if you slow down the drawing so much that the new image doesn't get drawn before the next screen refresh, then either part or all of the white image will make it to the screen before the new image gets drawn. That's the flash you are seeing. It's so fast that you barely recognize it, but the control is essentially being replaced by a white space, then a new image, all so fast that your eyes see it, though only as a flash. If it only partially draws in time, then you see tearing, as what gets rendered to the screen is partially the old image and partially the new image. That's nasty, but not quite as nasty as flashing.
Double buffering should help with flashing, but it isn't managed in such a way that you won't see something. What it could have done was draw everything to a back buffer and only swap it to the screen when ready. Unfortunately, it doesn't perfectly work that way, and probably because every control is painted separately of the rest.
Your issue is almost entirely due to graphical issues. WinForms controls are slow, and most of the rendering is done in the CPU rather than the GPU. Normally, that's good enough, but once you have enough controls, all the overhead means that not enough time is spent rendering images to the screen. WPF and alternative approaches like XNA (now continued with MonoGame) are all about leveraging the GPU for faster rendering of more complex images. Neither is as simple to use as WinForms.