i am improving speed and resource usage of an huge HIS application that have more than 200 winForms and they use entityContext like these :
private void someMethod()
{
var context = new entityContext();
var qry = context.someTable.Where(x=>x.condition);//bring thousands of records
...
... do some thing with result
...
//EOF method. here is problem :
/*
* is context will be free all the records that brings to ram
* in the end of method without using context.Dispose()?
* i think NO!
*/
}
is there any way to find all of the entityContext object that created in the form and dispose them?
if i use at winForms Closed event this.Dispose(true);
is it enough to dispose all of them?
public class myForm : System.Windows.Forms.Form
{
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
/*
* TODO:
* find all entityContext objects and dispose them
*/
this.Dispose(true);
}
}
i don't have time to edit all codes to wrap all entityContext
objects in a using{}
clause or add manually context.Dispose()
to them or etc ...
i am looking for a way to dispose all of them in the OnClosed()
event is these possible?