Reputation: 213
I am intrested if i use using (that close all connection) inside try catch
try{
using (var browser = new IE("https://www.bbvanetcash.com/local_kyop/KYOPSolicitarCredenciales.html"))
{
clsUtils.WriteToLog("Trying to login", true, true);
browser.Visible = false;
browser.TextField(Find.ByName("cod_emp")).Value = _company;
browser.TextField(Find.ByName("cod_usu")).Value = _strUser;
browser.TextField(Find.ByName("eai_password")).Value = _strPass;
browser.Button(Find.ByClass("grandote estirado azul")).Click();
browser.WaitForComplete();
clsUtils.WriteToLog("Logged ", true, true);
connected = true;
var cookie = browser.Eval("document.cookie");
CookieContainer Cc = GetCc(cookie);
} catch (Exception ex)
{
Console.WriteLine("(TryToLogin)-->Catching the {0} exception .", ex.GetType());
return connected;
}
}
and if one of steps gona fail the using gonna close the connection or it just gona go to catch?
Upvotes: 1
Views: 62
Reputation: 550
yes it does, if you are using a using
statement i has to implement the Idispose class.
so if you are using something like below
using (foo)
{
//...
}
the compiler will interpret like below.
try
{
//...
}
finally
{
foo.Dispose();
}
hope this helps.
Upvotes: 0
Reputation: 14253
MSDN:
The
using
statement ensures thatDispose
is called even if an exception occurs while you are calling methods on the object. You can achieve the same result by putting the object inside atry
block and then callingDispose
in afinally
block; in fact, this is how theusing
statement is translated by the compiler.
Upvotes: 1