how to show progress bar in monotouch while reading json file using http request
c#, httprequest, json, xamarin.ios
Solution
You must execute Getjsondata on a separate thread, something like this:
this.View.Add (loadingOverlay);
ThreadPool.QueueUserWorkItem (() =>
{
Getjsondata("http://polarisnet.my/polaristouchsales/Import/Products/product.json");
BeginInvokeOnMainThread (() =>
{
loadingOverlay.Hide ();
});
});
Now it will not block the main thread while downloading, and you can continue updating your UI while the download is in progress.
You should also read the documentation about threading in MonoTouch - it explains a bit what you can and what you can't do.
Problem
I am having trouble with displaying progress bar in my view. What is really happing is that when I click on the button, it start to read json file from server but until it is not yet finished you cannot do anything even adding progress bar to the view. Once it loads then everything start to work and showing progress bar. Do you have any idea how can I achieve this where once I click on the button it should start to show progress bar after it is completed I will trigger dismiss function to close progress bar. Here is my scripts: This is function where on button trigger it start to call function and add progress bar into view ``` this.View.Add (loadingOverlay); Getjsondata("http://polarisnet.my/polaristouchsales/Import/Products/product.json"); loadingOverlay.Hide (); ``` Here is Getjson function ``` public string Getjsondata(string URL) { HttpWebRequest request = null; StreamReader responseReader = null; string responseData = ""; try { request = (HttpWebRequest)HttpWebRequest.Create(URL); responseReader = new StreamReader(request.GetResponse().GetResponseStream()); responseData = responseReader.ReadToEnd(); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } finally { request.GetResponse().GetResponseStream().Close(); responseReader.Close(); responseReader = null; } return responseData; } ```