I have some code just like below. I am using my sql connection class
in a using
block. When it finishes the job, it disposes the connection as it is supposed to do. I also have some kernel classes in the same using block and i want them to get disposed when the using block that they are in finishes the job.
I searched a little bit but couldn't find an answer. Does the using
block dispose all objects that are inside it's blocks or does it just dispose the object that wrote as parameter? I hope i asked properly. I just want to understand and i don't want to keep writing unnecessary using blocks.
using (SqlConnection conn = new SqlConnection("server=" + serverName + ";initial catalog=" +
dataBase + ";integrated security=false;uid=" +
sqlUser + ";password=" + sqlPass + ";"))
{
Kernel kernel = new Kernel();
Sirket sirket = default(Sirket);
Fatura fatura = default(Fatura);
try
{
sirket = kernel.yeniSirket(TVTTipi.vtMSSQL,
"vt adı",
"vt kull adı",
"vt kull sifre",
"netsis kull adı",
"netsis kull sifre",
sube kodu);
fatura = kernel.yeniFatura(sirket, TFaturaTip.ftSFat);
fatura.OkuUst("A00000000000011", "C0001");
fatura.OkuKalem();
fatura.kayitSil();
}
finally
{
Marshal.ReleaseComObject(fatura);// those are releasing the objects. if i didn't use those methods would they get disposed immediately as using block finishes.
Marshal.ReleaseComObject(sirket);
kernel.FreeNetsisLibrary();
Marshal.ReleaseComObject(kernel);
}
}