Hello,
I'm working on an application that grabs some data from the web via
HttpWebRequest. I'm using a local objects method to get the data, but
the problem is that my form doesn't load until this method has
finished what it's doing.. which takes about 10-15 seconds. Here is
what I have:
Using System.Threading;
public class MyClass{
private MyObject mynewobject= new MyObject();
...
private delegate void GetDataDelegate(string url);
public MyClass(){
InitalizeComponent();
GetWebData(); // <- form isn't visible until after this
returns
this.lblStatus.Text = "finished";
}
private GetWebData(){
GetDataDelegate gdd = new
GetDataDelegate(mynewobject.RetrieveData);
// Initiate the asynchronous call
IAsyncResult ar = gdd.BeginInvoke("http://www.whatever.com/
file.txt", null, null);
Thread.Sleep(0);
this.lblStatus.Text = "getting data";
mld.EndInvoke(ar);
}
}
Again, what's happening is that the application starts, but I get no
visual cue that it has started, until after the GetWebData() call has
returned, sometimes it takes up to 30 seconds. I need the form and
components to be loaded first, but I'd also like to be pulling data as
soon as the program runs. What am I doing wrong? Thanks