C
C#8mo ago
jami1217

Program loads resources painfully slow (visual c#)

Hi. I’ve got a problem with my program which loads resource images into buttons painfully slow (as shown on video). Have you got any ideas why this happens?
11 Replies
SG97
SG978mo ago
You need to post code to figure out why it's slow I'm taking a guess, you're doing something heavy on the forms loaded/shown event handlers
Buddy
Buddy8mo ago
I assume this is Winforms? Only winforms acts in that way from experience Also Visual C# is not a thing, C# yes. Not Visual C#. Use modern tools not ancient tech developed in the beginning of the 2000s Use frameworks like WPF or Avalonia if it is desktop. They both allow you to customize the style of buttons without the use of images. And they are significantly faster than Winforms, also more modern. WPF is developed by Microsoft for exclusively Windows while Avalonia is an open source cross-platform UI framework for .NET, that also supports NativeAOT unlike WPF.
jami1217
jami1217OP8mo ago
I will have to clean up my code, it’s over 5000 lines in one form and the i will share it też, is it that bad?
SpReeD
SpReeD8mo ago
Over 5000 lines in one form - sounds like pure sequential code.
Buddy
Buddy8mo ago
Winforms is awful and ancient, yes.
canton7
canton78mo ago
It looks like it's re-rendering something many many times there
Joreyk ( IXLLEGACYIXL )
or instantiating the form X times
jami1217
jami1217OP8mo ago
Do u think that resource file with button images might be an issue? its actually 3000 now, had to clean this one up What if I wanted to try out WPF, would I have to write the entire app all over again? Or is there some correlation between WPF and winforms?
Buddy
Buddy8mo ago
Yes. WPF is xaml based, winforms is not. However if you wrote your backend separately from the UI it is possible to port it over fairly easily. Only thing would be the UI $rulesofwpf
MODiX
MODiX8mo ago
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Buddy
Buddy8mo ago
Make sure you read this! Especially this
❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
Want results from more Discord servers?
Add your server