Global timer for all users - c#

How would you go about creating a global timer all users use? Such as a tournament and every 24 hours the timer resets. How would you make all users see the same time and not base it off the client side?
I'd think to use a service like playfab or app42, but how would this work through them anyway?
Thanks

Since there is no code here im gonna tell you the how to but you will need to do research in order to achieve it probably.
You can have a time span in your server, and every time a user logs in you send the time span since the server started to run minus the time that the server has been running, and the client starts running its own timer taking into account that time span.
Im assuming you are working with a client server model here.

Related

asp web application that simultaneously takes in charges multiple accounts

Hello i'm trying to make an asp web application that send SMS to registered users whenever they receive an email , I'm a beginner when it comes to coding so I can't think of a pratique way to make it do that.
I thought of adding a timer and making it check every 5 minutes in the sql database for every user if there was something new but this will make the application slow assuming we have hundred of users.
I also thought of adding a trigger in the database and having it do the work but I can't find how to use sql trigger in visual studio, any Ideas that could help me ?
Thank you.
I thought of adding a timer and making it check every 5 minutes in the sql
database for every user if there was something new but this will make
the application slow assuming we have hundred of users ,
Why? Because I do not see that. Except slow means an average delay of 2.5 minutes. Then check every minute. Average delay down to 30 seconds.
I also thought of adding a trigger in the database and having it do the work but
I can't find how to use an sql trigger in visual studio , any Ideas that could
help me ?
Finding triggers? LEARN YOUR TOOLS. Seriously. But I personally would fire anyone using a trigger to then call an external program to send the SMS - the database is NOT where you want this.
Want it fast? Use a trigger to write a message to message broker (in sql server, it is a subsystem you likely do not know about because of not reading the documentation).
Have your app having some threads wait for messages there. There IS a special syntax to wait until a message arrives.
Voila, case closed.
May I suggest that you split up your code, put a message on a queue with the recipient and content of the SMS, and then create a separate webjob/service that subsbcribes to that queue and sends SMS whenever there is an entry there.
This gives you a clean separation of concerns, and removes the need to do polling to the database.
A couple of queues that are nice and easy to get started with:
Azure Storage Queue
Azure Service Bus Queue

Scheduler to do some tasks on time

I am working on a scheduler to do certain tasks like send email to users etc. Its a basic one which runs every 5 mins and do its job. I need to make some modifications into that so that it can work on demand. For example, I need to send email to a user at 11:00 AM, to another user at 11:02 AM. How can I make the scheduler to run on time without using a lot of resources on server. I know if I need to send emails every minute, then its sleep time should be one minute or less.
Is there any way to call it on demand or I need to have one thread active all the time to check when to do what and at that time activate scheduler or other process responsible for sending email.
Please suggest. Your inputs will be valuable.
Thanks.
If you need to send emails every minute it would be better to create a service and have the service poll the database every minute to look for work and sleep for 1 minute in between loops.
If you only need to run your code once an hour it would be better to use the Windows Task Scheduler.

Asp.net automate update of rss and save to database

I have this scenario:
an Asp.net/c# website with a rss reader/parser and a database. I would like to update the rss every x hours and save the new records in a database.
The indications I am receiving are that I need a dedicated server and a scheduler. I am not an expert about Asp but knowing that the server has a system time, it is natural to me thinking about using a timer.
I see that there is a timer in Asp.
Would it be possible to use a timer properly wrapped in the code, to get the functionality of the above scenario?
Yes you could use a timer inside a class (static or something that always has an instance activated) to accomplish this. One thing you are going to have to watch out for is that App Pools by default timeout and shutdown after 20 minutes of inactivity so you will want to change the settings to make it constantly run or make sure that something sends a request to the server every so often to keep the App Pool alive.

What is the preferred method to manage a timed event with a Web application?

I'm designing an ASP.NET 4.0 Web application where administrators may create an auction with an expiration. The expiration time would be stored in a database. How can I ensure that the auction ends at the predetermined time, considering the fact that an application instance may not be running when it is time? The application will be hosted with IIS7. I am considering Windows service, but I am wondering what other options are out there.
You can choose from two scenarios here:
Lazy with the web application
Active with a service
Lazy Scenario
Unless you have to interact instantly with the winner of an auction you could wait until the application starts and then let the application determine if there are any auctions that are expired. Collect them at that moment and handle them accordingly.
Active Scenario
Create a service that picks the first expiring auction from the DB. Store that DateTime and let the service sleep till the auction expires. Raise the service at that DateTime and process the expiring auction. Then let the service look for the next auction(s) to expire and let the service sleep again. And on and on.. I think The Windows Workflow Foundation contains all tools and requirements for this practice.
Something in between
Activate a scheduler that wakes up you web-app every hour/half hour/15 minutes and do the lazy stuff. Use a scheduler like HostMonitor.
A windows service that handles the timed events would be the best practice. Using a System.Threading.Timer in ASP.NET is bad juju; it MIGHT work in your case, because the change being made doesn't affect the UI directly, but I wouldn't bet on it working flawlessly. If you need to schedule events in the background of a web app, use a server app.
One thing to keep in mind; you may have hundreds or thousands of open auctions at a time. If you set a timer on every auction when it's opened, you'll have hundreds or thousands of sleeping threads managed by this server. I'd look only for auctions that would end before the next time you'd normally poll, and set timers for those auctions only. That would get you down to maybe a few dozen waiting threads. If you're writing the next eBay, though, even this will choke when you get hundreds of thousands, or millions, of auctions, and several hundred or thousand begin and end every minute.
If you want it to be 100% reliable, a Windows service that perform all scheduled logic is the way to go. As you say, you cannot trust a web application since it may not even be running.

Forms authentication and server time

I have a server that gets it time reset to 7 hours in the past. When this happens forms authentication no longer works.
When I resync the time with the server time it works again.
What could be causing this? It is actually and issue for me more so then changing the time, because I don't think it will be possible to keep all the clients and the servers in sync.
You can't have a production server with jumping time. Google "Windows NTP time synchronization" to find how to easily configure your servers to always be within microseconds of correct time.

Categories

Resources