Don't call
Dispose
as Suresh advised — this code does not take into account possible exceptions.
Do this:
(using Image foreImage = Image.FromFile(tbxForeImage.Text)) {
}
You should to it to all temporary objects implementing
System.IDisposable
.
Only if the object is used during the life time of the declaring class, dispose in the
Dispose
of the owner class, hierarchically. For a good example, look at
System.Windows.Forms.Form.Dispose
(which is
not System.IDisposable.Dispose
) and usage samples.
—SA