having beginner troubles with asynchronous calls in asp.net

G

Guest

Hi all, sorry if this is an over simple question but google isn't
coming through for me.

So I have a class that processes the data in an excel file, entering
the info row by row into our database. The public interface is as such:
public class ExcelToQueueEngine
{
public ExcelToQueueEngine(string ConnectionString)
{
//constructor
_connStr = ConnectionString;
}

public void ProcessFile(string pathToExcelFile, int archiveId)
{
//do my row processing
}
}

This processing can take 5+ minutes, so i'd like to call the
ProcessFile method asynchronously, and let the web user go on their
merry way. I have extensive logging/tracing in the ProcessFile method,
so I dont need ( and especially don't want) to have to tie up the aspx
page that calls this method to worry about the IAsynchResult return. So
basically the process is started and the web page returns, and the
processing thread does all the excel work. My aspx code is:

ExcelToQueueEngine eng = new ExcelToQueueEngine(_connStr);
AsynchProcessDelegate del = new AsynchProcessDelegate(eng.ProcessFile);
del.BeginInvoke(filePath, archiveId, null, null);

It seems to be that the BeginInvoke is called, but then the processing
stops as the page returns to the user. Any ideas what I'm doing wrong?

Thanks in advance.
 
B

Bruce Barker

you have to start a new tread to do the async processing, not use the
current request thread. when the current request completes (sends page to
browser), the thread is returned to the request pool. it may be processing
another request when the delegate fires, or if no requests have come along,
the thread may exit.

-- bruce (sqlwork.com)
 
G

Guest

don_spam,
As Bruce suggested, a Page Lifecycle isn't a good place to spawn an
asynchronous process that can take 5+ minutes. You could create a class with
a method to do this and store it in Global or in Application State, and have
some sort of callback mechanism to notify of results.
Here's a little piece I did recently that illustrates what's involved. This
isn't asynch- its just a background thread, but the concept is the same.

http://www.eggheadcafe.com/articles/20051223.asp

Hope that helps.


Peter
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top