1

I'm running an async thread with the use of Task.Factory.StartNew(() to generate sitemaps. My problem is that when I call my method:

Task.Factory.StartNew(() => generator.CreateSiteMapForSite

it builds the sitemaps every time.

In my method I check that it only needs to regenerate the files if it is older than one hour. Even though it still regenerate the files per each request, is there a way to handle this in a async thread ?

Nick N.
  • 12,902
  • 7
  • 57
  • 75
  • If you want help on code level, you should really post more code, for now I don't really get what you actually need to do. – Nick N. May 17 '13 at 06:47

2 Answers2

0

Since C# 5.0 you can use the async and the await keywords, have a look at this MSDN page for more information:

http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx

Nick N.
  • 12,902
  • 7
  • 57
  • 75
0

You can wrap around the task in an if and generate a new one if the sitemap doesn't exist or if exists read the file's modified datetime see if it's older than 1 hour.

The better solution is to setup a scheduled task to run every hour and rebuild the sitemap.

Checkout this question to find more on scheduled tasks.

Community
  • 1
  • 1
Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70