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 GetListingsAsyn cStub(int DelayInSeconds) ;
public string GetListings(int DelayInSeconds)
{
if (DelayInSeconds > 0)
{
System.Threadin g.Thread.Sleep( DelayInSeconds * 1000);
}
return "Success";
}
public class MyState
{
public object previousState;
public GetListingsAsyn cStub asyncStub;
}
[WebMethod]
public IAsyncResult BeginGetListing s(int DelayInSeconds, AsyncCallback
callback, object asyncState)
{
GetListingsAsyn cStub stub = new
GetListingsAsyn cStub(GetListin gs);
MyState ms = new MyState();
ms.previousStat e = asyncState;
ms.asyncStub = stub;
return stub.BeginInvok e(DelayInSecond s, callback, ms);
}
[WebMethod]
public string EndGetListings( IAsyncResult asyncResult)
{
MyState ms = (MyState)asyncR esult.AsyncStat e;
return ms.asyncStub.En dInvoke(asyncRe sult);
}
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.To String() + "<br>");
AsyncResult = service.BeginGe tListings(10, null, null);
ReturnValue = service.EndGetL istings(AsyncRe sult);
Response.Write( "Ended: " + DateTime.Now.To String() + "<br>");
Response.Write( ReturnValue);
What I'm seeing is, the page waits for the ten seconds to load. Does
ne1 see the obvious(to you) reason?
TIA,
~Gordon
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 GetListingsAsyn cStub(int DelayInSeconds) ;
public string GetListings(int DelayInSeconds)
{
if (DelayInSeconds > 0)
{
System.Threadin g.Thread.Sleep( DelayInSeconds * 1000);
}
return "Success";
}
public class MyState
{
public object previousState;
public GetListingsAsyn cStub asyncStub;
}
[WebMethod]
public IAsyncResult BeginGetListing s(int DelayInSeconds, AsyncCallback
callback, object asyncState)
{
GetListingsAsyn cStub stub = new
GetListingsAsyn cStub(GetListin gs);
MyState ms = new MyState();
ms.previousStat e = asyncState;
ms.asyncStub = stub;
return stub.BeginInvok e(DelayInSecond s, callback, ms);
}
[WebMethod]
public string EndGetListings( IAsyncResult asyncResult)
{
MyState ms = (MyState)asyncR esult.AsyncStat e;
return ms.asyncStub.En dInvoke(asyncRe sult);
}
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.To String() + "<br>");
AsyncResult = service.BeginGe tListings(10, null, null);
ReturnValue = service.EndGetL istings(AsyncRe sult);
Response.Write( "Ended: " + DateTime.Now.To String() + "<br>");
Response.Write( ReturnValue);
What I'm seeing is, the page waits for the ten seconds to load. Does
ne1 see the obvious(to you) reason?
TIA,
~Gordon