I am working on classified ads web application using asp.net Mvc-3 C#.
Every ad can share on social media like facebook,twitter,google plus ,linkedin.
I am calculating how many times ad is share on these website and saving this record in database.
Using this function
string jsonString = new System.Net.WebClient().DownloadString(URL-of-ad);
var serialize= new System.Web.Script.Serialization.JavaScriptSerializer();
var dictionary = serialize.Deserialize<Dictionary<string, string>>(jsonString);
var twitter = dict["count"];
var facebook= dict["share_count"];
// calculating for other website by this function
This is function is working fine but very time consuming for every ad .I have thousand of ads so i have to loop through thousand time and call this function for every ad.
I am calling this function twice in a day.
There is any other better and fast way to do this task?
Please give your suggestions.
You may think of improving your design
1 - Create a Windows Service and set it to run twice a day , most probably figure out when the traffic on your site is very minimal.
2- Move the Sharing count logic into windows service which will do it in another process and free up your main application.
3- Downloading something which is dependent upon the network speed so make yopur downloading Asynchronous rather than synchronous.