views:

55

answers:

1

I'm writing an ASP.NET MVC site where I need to have a "Tasks" application that runs alongside the website. Such a "Tasks" application would collect data at set intervals and insert it into the database.

Of course, I could write a simple Console Application and use the Windows Task Scheduler to run it, but my site is being hosted by GoDaddy and I only have medium trust permissions.

Are there any methods for implementing such functionality while not violating medium trust permissions?

One method that I'm considering is a method in the site itself that gathers data, waits for a long time, and then gathers data again. Would that interupt users' connection to the site?

+2  A: 

You can do it an ugly way.

Spin-off a thread which keeps on doing the tasks job. Initiate the thread with your own custom website request. The thread will keep running at the back-end.

nEEbz
Good idea! Will that affect users, though? Thanks!
Maxim Zaslavsky
Why is it considered ugly? A single thread that takes care of tasks seems like an elegant way.
Baddie
@Maxim: it will not affect the other users as long as the task itself is not processor extensive and slows down the server.
nEEbz
@Baddie: how would you kill the thread?
nEEbz
Why would you want to kill it if it's set to continually run jobs? You can have it access the database prior to each run to setup configurations or even look for a `KillMe` flag which would kill the thread.
Baddie
Great stuff - thank you! Just a quick question - where should I initiate the thread? I'm guessing that I should do it from the event handler that handles the starting of an application...
Maxim Zaslavsky
@Maxim Zaslavsky - Yes, `Application_Start` in the `Global.asax` file makes the most (and probably only) sense.
Baddie