asp timer and update panel - c#

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.

Related

how to have a dynamic text label with a loading bar

The last time I worked with .net was the 2.0 days. I've decided to pick it up to develop some Store/WP apps. Currently I've gotten the code part done, ie all my classes that do all the work but I am having trouble with the XAML/UI.
Basically I have a HUB control. In one of the hub sections (the first one), I need to have a control that needs to be updated as soon as the app is launched. This control (whether its a checkbox or a textblock) checks whether they can use the app. For all intents and purposes, this is done by a function that returns true/false.
So basically, when I launch the app I want this control to show a "loading.gif checking if you have your account enabled". While this is happening, my function is run and based on its return (true/false) I want it to say "Sorry, you can not access" or "Yes you can access".
What is the best control for doing this? A textblock seems like what I need, but can I add a gif in there?
Some additional info:
1) I will use a sleep function to delay the function for a couple of seconds. This is for UI purpose only.
2) I want the other hub sections to be disabled while my function checks (again, it should be a matter of milliseconds based on connection speed) but the other sections should be disabled.
3) In addition, if someone can point to me some good examples of XAML code or tutorials, that would be helpful.
Edit: looks like I can use a ProgressRing Control

Bing maps control hangs the back navigation

I recently ran into weird bug in Bing map control. In short, if the connection is poor and you press the hardware back button on page with map while the map is still loading some tiles, the navigation process hangs up (some times up to 10 or even more seconds). And in case when the time is more than 3 seconds the app will be "a little" not user-friendly and will not meet the technical certification requirements (5.1.3).
To repeat the bug you can create the app with two pages. First one with button to navigate to the second page. And the second page with just map control with high ZoomLevel (more than 14 for example). After the app launches, you navigate to the second page and move map to some unloaded area and then (without waiting for the download to complete) press the hardware back button. And also you somehow must "create poor" connection (in my case, simply disconnecting the device from the computer is enough).
And does anyone have any idea why this occurs and how to workaround it?
EDIT: The same bug can be observed in the Foursquare application for wp7 - if you go to the page where the place is shown on the map in full screen, then slide the map into an unloaded region and press the hardware button back.
It seems that the problem is in the Bing Map Control.
Hide the Maps control using the Visibility first, before you navigate out of the page. That way the control will become inactive and memory consumption of the page will decrease, thus allowing to switch pages faster.

Reloading another user's page

Assume you have made an internet game of tic-tac-toe or sth that is played between players. So, when a player inputs 'x' or 'o' or whatever is the input, the opponent must receive it on his pc.
I know how to make this with timer. But I'm interested in making it with an event. I mean, when the input is given we catch an event. Then, this event is reloading the opponent's page and he receives the info.
Is there any way I can achieve it? And does it worth it?
Thanks in advance for any responses!
There is something called HTTP Server Push. Usually, from what I read it is not recommended to use this since it seems to put a lot of load on the server which has to keep many connections open (for each browser that is connected).
So if I have to do this, I would stick with a polling scenario (timer) like you described, too.

Effecient Coding for low end CPU

I have a application built in Silverlight, which will run on a ATOM processor (was told around 1.6GHZ).
So far tested another application with lesser functions on another Mini PC and it can still run smoothly.
This application will be user interactive, and will have 4-5 different pages to be displayed.
So to navigate from page to page, I currently have 2 options, but not sure which is a better way considering the low end CPU. (pages are static, nothing generated on the fly)
1)Load the 4 - 5 pages during the onLoad event, shown the 1st page using Visibility.Visible.
The other pages will be Visibility.Collasped. This way, only need to toggle the Visibility property, pages need not be destroyed and re-created.
2)Initialize all the pages when loaded. Use Container.child to attach the wanted page. Not sure about the capability about this, but for other applications, I usually choose this method.
*P/S: I am okay if it takes a while to load,as the application will be loaded only once per day. As long as during the running period, it does not lag(using touchscreen) I am more than happy.
The main trick is to keep effects to a minimum. Animations etc. - not a problem in a normal application, more in a game or something. For normal LOB style apps, the CPU would not be too busy anyway.

Script does not stop while close the browser or click Abort

I wrote a webcrawler which calls a web page in a do while loop amount 3 seconds
totally there are 7000 sites... i parse the data and save it in my DB.
sometimes because the script is loading for a long time, i got a timeout in browser,
but in background i continues. I see that on my database.
Can I prevent this?.. Now it's just possible if I stop webserver.
Thank you and best regards.
Your web page is kicking off a server-side process. Killing your browser or closing it is not going to stop this. It sounds to me like a web page to control this is the wrong approach, and you should be looking at a connected form of application like a WinForms/WPF app. There would be ways to get this to work with ASP.NET, but they are not going to be simple. I think you have just chosen the wrong technology.
Starting an intensive, long running process like this from a web page is almost never a good idea. There are lots of reasons, but the main ones are :
1) If you get a timeout in the browser (this is your scenario) the data you have harvested may not be displayed.
2) What happens if you hit refresh in the browser? Will it attepmt to start the whole process again? this is an easy target for an attacker, if he wants to tie up all your server resources.
3) Is the data you are crawling really likely to change to such an extent that you need "live" crawling? 99% of cases would be served just as well with a background timed job running the crawl, and your front end just displaying the contents of the database.
I would seriously recommend you rethink your crawling strategy to something more controllable and stable.

Categories