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?
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.