C# How do I dispose an object before it is out of scope?

  • Thread starter Thread starter Milwaukee Broad
  • Start date Start date
M

Milwaukee Broad

Guest
I'm writing a C# WinForms .NET Framework app (VS 2019 Community) with the following code in Program.cs...


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
Application.Run(new frmMain(args[0], blAudioDevPresent)); // This line gives the warning below...



"Warning CA2000 Call System.IDisposable.Dispose on object created by 'new frmMain(args[0], blAudioDevPresent)' before all references to it are out of scope."

Assuming this is not a bug in VS 2019, how can I modify my code so frmMain is disposed? If it's as easy as "frmMain.Dispose();" where's the best place to put it?

Continue reading...
 
Back
Top