From 84b877a5ac52f49133d9ec95db328c63d77fb741 Mon Sep 17 00:00:00 2001 From: Islam Wahdan Date: Sat, 12 Dec 2015 01:25:00 +0200 Subject: [PATCH] Added Timeout to Menu fetching --- ACID/Engine.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ACID/Engine.cs b/ACID/Engine.cs index 4a6b5f6..6f790f4 100644 --- a/ACID/Engine.cs +++ b/ACID/Engine.cs @@ -15,6 +15,7 @@ using System.Drawing; using System.Threading; using System.IO.Ports; +using System.Net; namespace ACID { @@ -114,7 +115,27 @@ public Engine(String UserID, String Pass): base(UserID, Pass) /*Get Menu Data*/ try { - xmlFile.Load(@"https://storage-download.googleapis.com/menudata/MenuItems_Final.xml"); + // Create a request for the URL. + WebRequest request = WebRequest.Create("https://storage-download.googleapis.com/menudata/MenuItems_Final.xml"); + request.Timeout = 60000; + // If required by the server, set the credentials. + request.Credentials = CredentialCache.DefaultCredentials; + // Get the response. + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + + // Get the stream containing content returned by the server. + Stream dataStream = response.GetResponseStream(); + // Open the stream using a StreamReader for easy access. + StreamReader reader = new StreamReader(dataStream); + // Read the content. + string responseFromServer = reader.ReadToEnd(); + + // Cleanup the streams and the response. + reader.Close(); + dataStream.Close(); + response.Close(); + + xmlFile.LoadXml(responseFromServer); xmlFile.Save(@"./Backup/MenuItems.xml"); PBar.Auth.Invoke(PBar.myDelegate); ProgressTherad.Abort();