Do I have to Dispose Process.Start(url)?
Couldn't you just wrap it in a using
clause to ensure the GC does whatever it needs to do with it IF you are required to dispose of it? This would still allow a sort of "fire and forget" but not leave memory/resources in a bad state.
Probably overkill but there is a really good article on CodeProject about the IDisposable interface: http://www.codeproject.com/KB/dotnet/idisposable.aspx
No, you do not.
void Main()
{
Process result = Process.Start("http://www.google.com");
if (result == null)
{
Console.WriteLine("It returned null");
}
}
Prints
It returned null
From Process.Start Method (String) on MSDN (.NET Framework 4):
If the address of the executable file to start is a URL, the process is not started and null is returned.
(In general, though, the using
statement is the right way to work with IDisposable objects. Except for WCF clients.)
Starting the process is a native call which returns a native process handle, which is stored in the instance of Process that is returned. There are methods in Process that use the handle so you can do things like wait for the process to exit, or become idle.
Disposing the Process frees that handle. I agree with Jon, wrap it in a using clause.