Aug 24, 2017 07:24 PM
(This post was last modified: Aug 24, 2017 07:26 PM by _UnderDog.)
So I am still (slowly) developing an application which I released a Beta for a while ago ( https://hackforums.net/showthread.php?tid=5541855) which requires the entire form to slide from right to left.
The problem with this is the form contains many controls, most of which are hidden until needed though when using the following code:
https://pastebin.com/5G1pMqz3 (for some reason HF has a firewall against this code..)
It takes its time when loading, whereas if I compared it to an empty application, it is very smooth and instant.
I am still new to different concepts of coding but will converting everything to WFP help? This is the last thing I want to try as I'm using a theme and lots of controls. Any advice is appreciated!
DO NOT DEAL WITH THIS MEMBER
Aug 24, 2017 07:34 PM
(This post was last modified: Aug 24, 2017 07:40 PM by DeadKube.)
I did not look into your code or anything you've posted containing any code but having many controls in a WinForms application is known to cause glitchy or laggy behaviour. WPF will solve this problem as it can handle many, many controls at once.
However, there's this property that winforms have called doublebuffered which might just solve the issue for you without having to convert to WPF. Although I will highly suggest that you DO convert to WPF since it's newer and allows for so many customization options in regards to GUI development. You'll thank your future self for learning it.
Edit: now I looked at your code. Please don't use thread.sleep. it will block your GUI!! see this post for more information..
Thanks. Btw, it's multithreaded so it doesn't do that
Aug 24, 2017 10:04 PM
(This post was last modified: Aug 24, 2017 10:05 PM by KronosClouds.)
(Aug 24, 2017 07:24 PM)_UnderDog Wrote: So I am still (slowly) developing an application which I released a Beta for a while ago SNIP which requires the entire form to slide from right to left.
The problem with this is the form contains many controls, most of which are hidden until needed though when using the following code:
SNIP
It takes its time when loading, whereas if I compared it to an empty application, it is very smooth and instant.
I am still new to different concepts of coding but will converting everything to WFP help? This is the last thing I want to try as I'm using a theme and lots of controls. Any advice is appreciated!
Try this instead maybe makes everything run asynchronous
Code Public Shared Async Sub Slideina(ByVal F As Form, s As Integer)
Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
For i = 0 To s
Await Task.Delay(3)
F.Location = New Point(screenWidth - i, 0)
Next
End Sub
Suspend the layout while you do the changing, resume when ur done.
https://msdn.microsoft.com/en-us/library....110).aspx
Aug 24, 2017 10:26 PM
(This post was last modified: Aug 24, 2017 10:39 PM by _UnderDog.)
(Aug 24, 2017 10:04 PM)KronosClouds Wrote: Try this instead maybe makes everything run asynchronous
Code Public Shared Async Sub Slideina(ByVal F As Form, s As Integer)
Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
For i = 0 To s
Await Task.Delay(3)
F.Location = New Point(screenWidth - i, 0)
Next
End Sub
Although this moves at the same extremely slow rate if I were to reduce the wait to 0.3 it runs much more smoothly than sleep. Thanks! :)
EDIT: Realised it's as good as 0 or no delay line at all. Might have to some variable delays based on different system performance.
(Aug 24, 2017 10:09 PM)Barret Wrote: Suspend the layout while you do the changing, resume when ur done.
https://msdn.microsoft.com/en-us/library....110).aspx
Unfortunately, this made no difference to the situation - But I will use this for another feature. Thanks!
Instead of:
ByVal F As Form
Wouldn't it make sense to use:
ByRef f As Form
(Aug 24, 2017 08:35 PM)_UnderDog Wrote: Thanks. Btw, it's multithreaded so it doesn't do that
Explain? You're not setting a particular property to false are you and invoking this from a separate thread which needs to join the UI thread?
I think we need to see how you are threading this because I highly doubt you're doing it properly if you think multi-threading by itself fixes application hang problems magically.
(Aug 25, 2017 07:23 PM)0xDEAD10CC Wrote: Explain? You're not setting a particular property to false are you and invoking this from a separate thread which needs to join the UI thread?
I think we need to see how you are threading this because I highly doubt you're doing it properly if you think multi-threading by itself fixes application hang problems magically.
Probably there's something wrong in his threading.
Aug 26, 2017 12:37 PM
(This post was last modified: Aug 26, 2017 12:39 PM by 0xDEAD10CC.)
(Aug 25, 2017 11:53 PM)Rhez Wrote: Probably there's something wrong in his threading.
This is what I was already suggesting. He had Thread.Sleep on a method which deals with UI code, he's saying it doesn't freeze the form because he's multi-threading, but what he doesn't understand is that you obviously can't do cross thread operations like this without setting that value which is only intended for debugging purposes, and this would end up making the threading completely pointless in that case and probably would degrade the performance of the application more than not multi-threading at all, with all the thread context switching and joins.
Aug 26, 2017 05:19 PM
(This post was last modified: Aug 26, 2017 05:20 PM by _UnderDog.)
(Aug 26, 2017 12:37 PM)0xDEAD10CC Wrote: This is what I was already suggesting. He had Thread.Sleep on a method which deals with UI code, he's saying it doesn't freeze the form because he's multi-threading, but what he doesn't understand is that you obviously can't do cross thread operations like this without setting that value which is only intended for debugging purposes, and this would end up making the threading completely pointless in that case and probably would degrade the performance of the application more than not multi-threading at all, with all the thread context switching and joins.
I would agree. I'm completely self-taught with vb.net and I don't spend very much time coding but atm I just run that code in a different thread, like a background worker I suppose. And it does make more sense to use "Await Task.Delay(x)"
Right now I'm redesigning the entire application in WPF to try and solve the problem. Thanks everyone for the help and feedback :>
In the code you made the thread sleep? Is that the main thread?
(Aug 26, 2017 10:09 PM)Xogg Wrote: In the code you made the thread sleep? Is that the main thread?
I used this code to run it in a different thread.
Code Dim thread As System.Threading.Thread
thread = New System.Threading.Thread(sub or function)
thread.Start()
(Aug 26, 2017 11:45 PM)_UnderDog Wrote: I used this code to run it in a different thread.
Code Dim thread As System.Threading.Thread
thread = New System.Threading.Thread(sub or function)
thread.Start()
No, see you don't understand that this won't work to update the UI in any way unless you're on that thread. Multi-threading the UI like this is worse than not multi-threading at all...
|