Asp.Net Stopwatch C# - c#

I have a web-based (ASP.NET C#) game platform that has a racecourse. Each user should complete this racecourse. When an online user starts the game, stopwatch starts to count and shows the time in simultaneously. I have a callback method and timer which calls this method every 1 minute. However, the problem is that while an online user is playing the game and other online user starts playing the game, stopwatch shows the time which is belong the first online user, however, it has to Show 0 for new online user. I cannot handle this problem. Do you have any idea without using javascript and jquery?
Thank you

You'll have have to have a place to store the starttime for each player.
If you do not want to do that clientside - using javascript, you'll have to do it serverside, using the session cache.

Related

How do I recognize someone navigated to my app?

Is there a specific function which is called when someone navigates from the home screen to my app again?
In my application i'm requesting data from a server and i don't want it to be requested everytime someone navigates to my app. The request should come at a maximum of once in an hour. Would a timer keep running when i go from the app to the start screen, or would it stop or keep it's state at maybe 58 minutes?
I'm using c# Windows Phone 8.
If you wish to make a request once an hour maximum, you could simply save the result with a DateTime to evaluate if the request can be made again or not, regardless of the navigation state, but if you really need to know, you can go to the App.xaml code-behind. There, you will find some methods that are useful.
The Application_Launching method is called only when the app starts for the first time. It will not be executed after that. Otherwise, if someone left your application and comes back later, the Application_Activated method will be called.
I also suggest you consult this diagram displaying a Windows Phone app lifetime. The page describes the diagram and gives additional insights.

Resetting app data setting using background worker in wp7

I am building a WP7 app. I want to reset my app data settings at a given time. I have tried resetting by comparing the hour of the given time and "DateTime.Now.Hour" when the Main Page loads(i.e. when I open the app at the given time). But if I open the app after the given time, it doesn't reset at all. So, I want to know if there is any way to solve this. I haven't used Background Worker before but I think it can help. Can somebody suggest me a way out of it?.
Thanks in advance
You cannot run apps permanently in the background on Windows Phone. When your app launches or is activated you should check if the delete time has passed (DateTime.Now > deleteTime).
You could consider using a background agent that can run every 30 mins, but beware the limitations especially on 256MB devices.

How to check User Activity value repeatedly in website

I'm building a website using ASP.NET. It's a game which I connect two users randomly to play with each other.
What I need to do is when one of these two players logs out or has been inactive for a certain time, I finish the game and send the other player to some page to tell him or her the game is over.
My problem is I can't figure out how to track the user status every while. I know that ASP.NET has (LastActivityDate), but how can I check this value repeatedly every 30 seconds for example?
lets say you have 2 users
each user pings the server ( ajax) every 2 sec [using javascript's setInterval] and increase a counter - or set a new time in the Application or Cache ) - global accessed objects
once in a while - you scan those structures - and if the value ( lets say of DateTime) - is larger by X - so someone has stopeed sending pings - and thats how you know that someone has gone.
You should use jQuery or another Javascript library for using ajax simply. You need also to use 'setInterval' function that will verify that user still active.
Links:
http://api.jquery.com/jQuery.ajax/
http://www.w3schools.com/ajax/ajax_intro.asp

asp timer and update panel

I have a small web application I am working on that is basically a radio player that plays live radio. On the player we have the schedule and what's playing now etc. I used a asp timer and update panel to update various content on the player mainly the 'what's playing now' bit.
Last time we tried to use the asp timer and update panel on our website it crashed the webserver in minutes because the cpu went to 100% and it could not handle that many postbacks. I am wondering what the best way of optimizing this radio player is so that it does not crash?
I have thought I could load all the content in on page load in hidden fields then use jquery? Sounds a bit messy but open to ideas?
Creating some Javascript that updates the update panel on certain timestamps isn't that much work. Send the expected end-time to the browser and let it update once the song ends.
You can even send a list of queued songs to the browser so it only has to update the data once in a while. (depending on play list style)
Make sure the update panel server side uses as much as possible cached output so it does not have to find the currently playing song. IIRC an update panel has quite some overhead, calling a clean JSON request to only retrieve the currently playing song might be much cleaner.
check view state is not enabled - this will quickly eat up memory.
You could use JQuery to fill in a portion of your page (or several portions) after the initial PageLoad. I have learnt how to do this recently and it feels better than the timer and update panels. See this post for how I achieved it - the answer from jwiscarson has the detail.

ASP.net - building online basketball manager how to keep game logic running

my question is this, how can i simulate a text base basketball game in a web application.
The game logic class is ready and in use in my WPF application, however I want to transfer it to a web base application.
But I have no idea how to keep the game thread a live + updating the UI every second.(only text update are required).
Any ideas ?
Thanks.
Maybe you could try to start the main thread in the application_start method of your global.asax file.
But to refresh UI, it's the client browser that will request the data to the server every "x" seconds (with a setTimeout).

Categories