How do you automate a process?

C

Cirene

i am creating an asp.net auction website

how do i create a process that will "end" the auction when it's time

obviously i don't want to sit at a browser and keep refreshing the page

i'm not sure if i can install an application on the server too (not
allowed?)

thanks...
 
M

Mark Rae [MVP]

how do i create a process that will "end" the auction when it's time

I'm not sure I understand your problem...

/* show the active acutions */
SELECT * FROM MyAuctions
WHERE EndDate > getdate()

/* show the ended acutions */
SELECT * FROM MyAuctions
WHERE EndDate < getdate()

SELECT EndDate FROM MyAuction
WHERE AuctionID = 12345

if (Convert.ToDateTime(<EndDate>) < DateTime.Now)
{
// tell the user the auction has ended
return;
}

etc
 
C

Cirene

I was thinking of doing it this way, but these are exclusive type auctions
with not much traffic to the site. I was hoping that at the exact time it
ends to email me a notification, even if no one visits the site. But, this
is a good solution. Thanks John!
 
C

Cirene

Thanks.

Mark Rae said:
I'm not sure I understand your problem...

/* show the active acutions */
SELECT * FROM MyAuctions
WHERE EndDate > getdate()

/* show the ended acutions */
SELECT * FROM MyAuctions
WHERE EndDate < getdate()

SELECT EndDate FROM MyAuction
WHERE AuctionID = 12345

if (Convert.ToDateTime(<EndDate>) < DateTime.Now)
{
// tell the user the auction has ended
return;
}

etc
 
R

Robert Dunlop

Cirene said:
i am creating an asp.net auction website

how do i create a process that will "end" the auction when it's time

obviously i don't want to sit at a browser and keep refreshing the page

i'm not sure if i can install an application on the server too (not
allowed?)

thanks...

Obviously your options are a bit limited if you are running on someone
else's host, but it's not too hard to implement threads that run separate
from your page handling code. I have done this in a few apps on different
hosting services without any issues. Here are a couple of paths I've found
to work pretty well:

1. Use ThreadPool.QueueUserWorkItem() to launch a thread, which will
continue to exist until it terminates.

2. Make a web service and include a method that returns void, and mark it
with [SoapDocumentMethod(OneWay = true)]. This makes the method a
"fire-and-forget" method, the client will return immediately after calling
it and the method will run in its own thread until it completes.

However, you will need to be considerate of the fact that you are in a
shared environment, or it could raise issues with your host. Some general
guidelines:

* Threads in the thread pool are limited, if they are used up by multiple
long-running threads then requests will start blocking. Instead of
launching multiple threads, such as one for each auction, check to see if a
thread is already running your task, and if so pass the work on to it rather
than launching another thread. Also, you can check on the number of
available threads using ThreadPool.GetAvailableThreads().

* Don't write background threads that block for long periods of time. A
good patter for long-running tasks is to use Thread.Sleep() to idle the
thread and wake it up at periodic intervals, then perform a quick task and
go back to sleep. For example you could have a task for you auctions that
sleeps for a half hour at a time then checks for auctions near their end.

* If you were to use a "fire-and-forget" web service for this, make sure it
is either inaccessible from the internet, and/or use some form of
authentication to make sure no one else can launch it. Failure to do so
would be leaving a doorway open for a denial of service attack against you
and anyone else hosted there.

* Be sure to use exception handling to trap any possible exception that
could occur in your worker thread, as an unhandled exception could cause
your application to terminate.

Robert Dunlop
 
C

Cirene

Thanks for the thorough response Robert...

Robert Dunlop said:
Cirene said:
i am creating an asp.net auction website

how do i create a process that will "end" the auction when it's time

obviously i don't want to sit at a browser and keep refreshing the page

i'm not sure if i can install an application on the server too (not
allowed?)

thanks...

Obviously your options are a bit limited if you are running on someone
else's host, but it's not too hard to implement threads that run separate
from your page handling code. I have done this in a few apps on different
hosting services without any issues. Here are a couple of paths I've
found to work pretty well:

1. Use ThreadPool.QueueUserWorkItem() to launch a thread, which will
continue to exist until it terminates.

2. Make a web service and include a method that returns void, and mark it
with [SoapDocumentMethod(OneWay = true)]. This makes the method a
"fire-and-forget" method, the client will return immediately after calling
it and the method will run in its own thread until it completes.

However, you will need to be considerate of the fact that you are in a
shared environment, or it could raise issues with your host. Some general
guidelines:

* Threads in the thread pool are limited, if they are used up by multiple
long-running threads then requests will start blocking. Instead of
launching multiple threads, such as one for each auction, check to see if
a thread is already running your task, and if so pass the work on to it
rather than launching another thread. Also, you can check on the number
of available threads using ThreadPool.GetAvailableThreads().

* Don't write background threads that block for long periods of time. A
good patter for long-running tasks is to use Thread.Sleep() to idle the
thread and wake it up at periodic intervals, then perform a quick task and
go back to sleep. For example you could have a task for you auctions
that sleeps for a half hour at a time then checks for auctions near their
end.

* If you were to use a "fire-and-forget" web service for this, make sure
it is either inaccessible from the internet, and/or use some form of
authentication to make sure no one else can launch it. Failure to do so
would be leaving a doorway open for a denial of service attack against you
and anyone else hosted there.

* Be sure to use exception handling to trap any possible exception that
could occur in your worker thread, as an unhandled exception could cause
your application to terminate.

Robert Dunlop
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top