question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[suggestion] move Dispose(bool disposing) from Form1.Designer.cs to Form1.cs

See original GitHub issue

Issue description

What do you think about moving this method for newly created form? This will save a few seconds of time for each form 😃 But most importantly It’s location raises many questions for beginners (ppl afraid to modify anything in *.Designer.cs): https://stackoverflow.com/questions/1052147/how-do-i-extend-a-winforms-dispose-method https://stackoverflow.com/questions/672980/dispose-on-user-controls-really-meant-to-edit-the-designer-cs-file https://stackoverflow.com/questions/4382693/when-modifying-disposebool-in-a-winforms-generated-designer-cs-file-is-it-nec and so on…

Also it can be modernize a bit.

protected override void Dispose(bool disposing)
{
    if (disposing && (components != null))
    {
        components.Dispose();
    }
    base.Dispose(disposing);
}

To

protected override void Dispose(bool disposing)
{
    if (disposing)
    {
        components?.Dispose();
    }

    base.Dispose(disposing);
}

Or are we afraid that this method will simply be deleted, or corrupted by the user?

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
merriemcgawcommented, Feb 14, 2023

We’ll take this up internally, and explore whether or not this is the right way to ensure that our components are disposed. In general, we like this idea and just want to think about it 😄

2reactions
elachlancommented, Feb 12, 2023

I think this would be more correct than what we have now for the new form template. Its not “generated” code and isn’t updated as far as I know. It would allow easier visibility on what is happening. The *designer.cs hides implementation from users to a degree and this makes it harder to learn the lifecycle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When modifying Dispose(bool) in a winforms generated . ...
When modifying Dispose(bool) in a winforms generated .Designer.cs file is it necessary to move Dispose to the main code file?
Read more >
dispose (bool): no suitable method found to override
To me it seems, you try to override void Dispose(bool), to perform ... to perform some action in the moment, when the form...
Read more >
Windows Forms Designer Problem When Renaming New ...
I created a solution with two test projects. I created a Windows Forms project which, of course, defaulted to names Form1.cs and Form1.Designer....
Read more >
How do I dispose something defined in a form?
To dispose of resources defined in a user control, you can override the Dispose(bool disposing) method in the user control's code-behind file ( ......
Read more >
Form1.Designer.cs
Dispose (disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found