Long process in ASP.NET

G

Guest

What's the best system for a process that could take a long time, minutes,
hours

a) Creating a webservice that calls a Thread?
b) Creatinga webservice with [SoapDocumentMethod(OneWay=true)]
c) Any better way? without using an external program?

Thanks
Al
 
L

Li-fan Chen

Hi Albert,

Another way is queuing jobs. MSMQ or Service Broker (SQL Server 2005).

1. Create a job class instance in .NET and assign a unique id to it (GUID,
auto incr in some table).

public class Job
{
string ID;
}

1.1 This class is a great place to put in the criterias required to perform
the long-running task.

2. Track the job. For example: with the Ticket (Job.ID), INSERT TABLE
tblJobs SET Completed = FALSE WHERE ID = @ID

3. When the job is done make sure the job executor updates the completion
bucket to say the job is done.

UPDATE tblJobs SET Completed = TRUE WHERE ID = @ID

4. Until then, give your response page the Job ID. It will refresh (great
place to add an AJAX enabled progress bar) and use that ticket to check
whether the job is done or not in the completion bucket:

With the Ticket (Job.ID), Query for SELECT TOP 1 WHERE Completed = TRUE AND
ID = @ID

Others are welcomed to recommend a better way.

Best regards,
-- Li-fan
 
L

Li-fan Chen

Hi,

Just an appendix: you can also peek into the queue to see if the job has
been dequeued. That tells you the job is done as well. Depending on the size
of the queue, it might be worth it to save the DB round-trip.

Best personal regards,
-- Li-fan

--
Li-fan Chen
Software analyst/developer, Entrepreneur
Markham, Ontario, Canada
Li-fan Chen said:
Hi Albert,

Another way is queuing jobs. MSMQ or Service Broker (SQL Server 2005).

1. Create a job class instance in .NET and assign a unique id to it (GUID,
auto incr in some table).

public class Job
{
string ID;
}

1.1 This class is a great place to put in the criterias required to
perform the long-running task.

2. Track the job. For example: with the Ticket (Job.ID), INSERT TABLE
tblJobs SET Completed = FALSE WHERE ID = @ID

3. When the job is done make sure the job executor updates the completion
bucket to say the job is done.

UPDATE tblJobs SET Completed = TRUE WHERE ID = @ID

4. Until then, give your response page the Job ID. It will refresh (great
place to add an AJAX enabled progress bar) and use that ticket to check
whether the job is done or not in the completion bucket:

With the Ticket (Job.ID), Query for SELECT TOP 1 WHERE Completed = TRUE
AND ID = @ID

Others are welcomed to recommend a better way.

Best regards,
-- Li-fan

--
Li-fan Chen
Software analyst/developer, Entrepreneur
Markham, Ontario, Canada
Albert Pascual said:
What's the best system for a process that could take a long time,
minutes,
hours

a) Creating a webservice that calls a Thread?
b) Creatinga webservice with [SoapDocumentMethod(OneWay=true)]
c) Any better way? without using an external program?

Thanks
Al
 
G

Guest

Actually I was looking for something like somebody presses the button on the
webpage and the job starts!

Li-fan Chen said:
Hi Albert,

Another way is queuing jobs. MSMQ or Service Broker (SQL Server 2005).

1. Create a job class instance in .NET and assign a unique id to it (GUID,
auto incr in some table).

public class Job
{
string ID;
}

1.1 This class is a great place to put in the criterias required to perform
the long-running task.

2. Track the job. For example: with the Ticket (Job.ID), INSERT TABLE
tblJobs SET Completed = FALSE WHERE ID = @ID

3. When the job is done make sure the job executor updates the completion
bucket to say the job is done.

UPDATE tblJobs SET Completed = TRUE WHERE ID = @ID

4. Until then, give your response page the Job ID. It will refresh (great
place to add an AJAX enabled progress bar) and use that ticket to check
whether the job is done or not in the completion bucket:

With the Ticket (Job.ID), Query for SELECT TOP 1 WHERE Completed = TRUE AND
ID = @ID

Others are welcomed to recommend a better way.

Best regards,
-- Li-fan

--
Li-fan Chen
Software analyst/developer, Entrepreneur
Markham, Ontario, Canada
Albert Pascual said:
What's the best system for a process that could take a long time, minutes,
hours

a) Creating a webservice that calls a Thread?
b) Creatinga webservice with [SoapDocumentMethod(OneWay=true)]
c) Any better way? without using an external program?

Thanks
Al
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top