I have a basic form that will attempt to load and play a video of the user. The form can be called from a public static ShowDialogForm method. That method will attempt to initialize a video if successful then the form is returned otherwise the action is canceled. At my office we use a refactoring tool, and it is complaining about the lack of a using statement in my method. So my question is benifit, if any does the using statement offer in this instance.
This is the original code
public static DialogResult ShowDialogForm(VideoNames videoName, Course course, IWin32Window parent)
{
FlashPlayer form = new FlashPlayer();
if (form.Initialize(videoName, course))
{
return form.ShowDialog(parent);
}
else
{
return DialogResult.Cancel;
}
}
This is the code suggested by the refactoring tool
public static DialogResult ShowDialogForm(VideoNames videoName, Course course, IWin32Window parent)
{
using (FlashPlayer form = new FlashPlayer())
{
if (form.Initialize(videoName, course))
{
return form.ShowDialog(parent);
}
else
{
return DialogResult.Cancel;
}
}
}
IDisposibleand using ausingautomatically callsDispose()when you are done using the form.