diff --git a/LearnositySDK/Request/Remote.cs b/LearnositySDK/Request/Remote.cs index 18496cc..3f1d6c0 100755 --- a/LearnositySDK/Request/Remote.cs +++ b/LearnositySDK/Request/Remote.cs @@ -7,6 +7,7 @@ using System.IO; using LearnositySDK.Utils; using System.Diagnostics; +using System.Threading; namespace LearnositySDK.Request { @@ -178,10 +179,11 @@ private Remote request(string url, string post = null, JsonObject options = null } } + Stopwatch timer = new Stopwatch(); + timer.Start(); + try { - Stopwatch timer = new Stopwatch(); - timer.Start(); using (this.result = this.hr.GetResponse()) { using (StreamReader sr = new StreamReader(this.result.GetResponseStream())) @@ -190,16 +192,17 @@ private Remote request(string url, string post = null, JsonObject options = null } } this.status = "200"; - timer.Stop(); - this.time = timer.Elapsed.Seconds; } catch (WebException e) { using (this.result = e.Response) { - using (StreamReader sr = new StreamReader(this.result.GetResponseStream())) + if (this.result != null) { - this.responseBody = sr.ReadToEnd(); + using (StreamReader sr = new StreamReader(this.result.GetResponseStream())) + { + this.responseBody = sr.ReadToEnd(); + } } } this.status = e.Status.ToString(); @@ -207,6 +210,9 @@ private Remote request(string url, string post = null, JsonObject options = null this.errorMessage = e.Message; } + timer.Stop(); + this.time = timer.Elapsed.Seconds; + this.process(); return this; }