How often should I call getblocktemplate? I'm building a basic Bitcoin client in c# to better understand the mining protocol.
I need help understanding Getblocktemplate. I have read the Getblocktemplate wiki, but I'm still having an issue understanding the protocol. The wiki states "Since you're making all the blocks yourself, you really don't ever need to get another template... until it's invalid". When is the template considered invalid? How often do I need to call Getblocktemplate?
If a new block is mined every 10 minutes, with some coins that is every 1 minute, do I need to call Getblocktemplate every 10 minutes (1 minute depending on the coin) so that I have the latest "previousblockhash"?

The steps I'm using:


Make a rpc call to bicoind server for Getblocktemplate.
Parse data and build a merkle root.
Build a block header (version, previousblockhash, merkleroot, curtime, bits, nonce).
Get a header hash. headerHash = Hash(version, previousblockhash, merkleroot, curtime, bits, nonce).
Repeat step 4 by 2^32 increments of nonce.
I understand I can then increment "curtime", (which doesn't have to be precise?), so increment curtime and then repeat step 5. 


Is this correct? 

How long can I keep incrementing "curtime" before I need to call getblocktemplate again?

At what point do I need a new block (i.e. new previousblockhash and new merkle root)?
One fundamental, expected way to make a valid template invalid: someone else finds a block, and it's time to switch.

You can technically keep incrementing "curtime" until it's 2 hours in the future, though my gut tells me I should try to avoid pushing "curtime" anywhere near that far into the future until after I've exhausted everything else.  I haven't spent too much time looking into GBT, but you should be able to make at least some changes to the coinbase data on the generation transaction (you probably won't have complete freedom, as I'm guessing there's a way for the pool to force things like /P2SH/ to show up in there for example) to get a different Merkle root.  People often call this the "extranonce".

As for when you should ask for a new template, immediately after the spot you quoted in the bitcoin wiki, it says this:


  If your template included a "longpollid" key, you can queue a request for a new template to be executed as soon as the pool decides you should change. This is the same as any other template request, except that you include the "longpollid" parameter that the pool provided in your request. If there is already a new template, the pool might respond immediately, so be sure not to depend on a delay!


In other words, you should be able to do a "long poll" request that won't return any data until the pool server decides for you that it's time for a new template.  You definitely shouldn't rely on guessing that "desired block interval" ought to be good enough.