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