Server-Side Asynchronous Web Method help


Simple Simon

Hi, excuse the long post and plz read on :)

My web application needs to upload a .csv & .zip file, as well as,
import the .csv into a (Sql2000) table and unzip the .zip file to a
directory on the web server every day. Since I don't want the
application to time-out, I'm putting all this into a Server-Side
Asynchronous Web Method.

I've starting out by writing this test web service:

public delegate string GetListingsAsyncStub(int DelayInSeconds);

public string GetListings(int DelayInSeconds)
if (DelayInSeconds > 0)
System.Threading.Thread.Sleep(DelayInSeconds * 1000);
return "Success";

public class MyState
public object previousState;
public GetListingsAsyncStub asyncStub;

public IAsyncResult BeginGetListings(int DelayInSeconds, AsyncCallback
callback, object asyncState)
GetListingsAsyncStub stub = new

MyState ms = new MyState();
ms.previousState = asyncState;
ms.asyncStub = stub;

return stub.BeginInvoke(DelayInSeconds, callback, ms);

public string EndGetListings(IAsyncResult asyncResult)
MyState ms = (MyState)asyncResult.AsyncState;
return ms.asyncStub.EndInvoke(asyncResult);

And this is in my Page_Load page that will be scheduled to run:

string ReturnValue;
IAsyncResult AsyncResult;

ImportService service = new ImportService();

Response.Write("Started: " + DateTime.Now.ToString() + "<br>");
AsyncResult = service.BeginGetListings(10, null, null);

ReturnValue = service.EndGetListings(AsyncResult);
Response.Write("Ended: " + DateTime.Now.ToString() + "<br>");


What I'm seeing is, the page waits for the ten seconds to load. Does
ne1 see the obvious(to you) reason?



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question