0

I am creating a little Website which is basically a leaderboard from a specific game.

Im using C#6 - 4.6.

I am using a Webhosting by 1and1.

My question/problem: The leaderboard has to update itself every 10 minutes. I am using an API to get the newest informations and then save it into a mysql db.

I cannot use cronjobs(using Windows hosting) and i cannot create scheduled tasks (Only webhosting and not a server...).

I was talking to support, but they could not help me because of lagg of knowledge in c# and win hosting.

So i tested something in my Visual studio: I created a seperate Thread which does the update, wait for X minutes and then does it again (infinit, until i stop it). Works like a charm on my pc, but when i publish it to the server, the thread starts executing and actually writes that into the log, but after around 10 seconds there is no more respond from the thread.

Everything from that thread is running serverside.

Can someone explain this to me or has a better idea on how to solve it?

If you need any code snippets, please let me know!

Thanks in advance, Markus

  • 2
    I wouldn't expect a background thread in a web application to be continuously running. It's basically at the mercy of the web server, which rightly expects a web application to be a request/response system only. This would especially be true on any system with shared resources where the system owner wants to be fair to everyone. Can these updates not simply be fetched when the page loads? Or does that take too much time? Perhaps a separate host can run the background process? – David Oct 15 '17 at 11:17
  • The update takes up to 5 minutes right now, so a launch on load does not work. The thread does not need any cpu. Its basically just waiting for another server to send the data and then inserts them into the database. ( i do not have access to that other server, im just sending a request to it). Next bad thing: I do not have remote access to the database. That means i can only update it from that one server... That should eliminate the seperate host.. – Markus Friedl Oct 15 '17 at 11:26
  • You can try using a `BackgroundWorker` instead of a separate thread explicitly. If your web host is killing any background processes then you'd simply have to ask *them* how they would allow it. They just might not. And you can use a separate host if you can just expose some page or service endpoint which that host can invoke. – David Oct 15 '17 at 11:28
  • 2
    Use a library like https://www.hangfire.io/. Designed for Asp.Net it handles exactly these kind of scenario's – Peter Bons Oct 15 '17 at 11:31
  • You can use [My Web Cron](https://www.mywebcron.com/) or similar service to start leaderboard update periodically. – Ňuf Oct 15 '17 at 12:26
  • The My Web Cron thing sounds pretty good, but without paying you can only have 1 minute Timeout pagecalls... that will not work in our case. Updates take between 3 and 5 minutes. I will test the background worker, but i guess they are blocking it aswell. I might just call them today. – Markus Friedl Oct 16 '17 at 09:47

0 Answers0