Doh! Yes, in a previous life I would have used (excuse my VB) if (counter mod 10000) = 0
Is that the most efficient way to go? Certainly looks the cleanest. Dylan. ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of Greg Kennedy Sent: Monday, 17 May 2010 1:59 PM To: ozDotNet Subject: Re: How To do something every so often Hi Dylan, The common way to do it is using the Modulus function while{ if(counter%10000==0) { //do stuff } } Greg On Mon, May 17, 2010 at 1:30 PM, Dylan Tusler <[email protected]<mailto:[email protected]>> wrote: I was just writing a very simple little console app to move data from one file to another (under certain conditions) and I thought it would be beneficial if the output gave some feedback that something was happening. So, for each file, for every 10,000 lines processed, I put a "." out via Console.Write Seems simple enough, but I was wondering how you would go about determining that you got through 10,000 lines? Here was my approach: int counter=0; while ((line = fs.ReadLine()) != null) { // do stuff - snipped counter++; if ((int)(counter/10000)*10000 == counter) { Console.Write("."); } } This works fine in my application, but I was wondering what different approaches were available, especially considering there is a bit of wasted math here, seems like it could be costly for a very long running process. (In my situation, the app will be processing many millions of rows of data, so small savings could add up to a big net saving.) Cheers, Dylan Tusler ------------------------------------------------------------------------------------------------- To find out more about the Sunshine Coast Council, visit your local council office at Caloundra, Maroochydore, Nambour or Tewantin. Or, if you prefer, visit us on line at www.sunshinecoast.qld.gov.au<http://www.sunshinecoast.qld.gov.au/> This email, together with any attachments, is intended for the named recipient(s) only. Any form of review, disclosure, modification, distribution and or publication of this email message is prohibited without the express permission of the author. Please notify the sender immediately if you have received this email by mistake and delete it from your system. Unless otherwise stated, this email represents only the views of the sender and not the views of the Sunshine Coast Regional Council. maile 3_0_0 ------------------------------------------------------------------------------------------------- To find out more about the Sunshine Coast Council, visit your local council office at Caloundra, Maroochydore, Nambour or Tewantin. Or, if you prefer, visit us on line at www.sunshinecoast.qld.gov.au This email, together with any attachments, is intended for the named recipient(s) only. Any form of review, disclosure, modification, distribution and or publication of this email message is prohibited without the express permission of the author. Please notify the sender immediately if you have received this email by mistake and delete it from your system. Unless otherwise stated, this email represents only the views of the sender and not the views of the Sunshine Coast Regional Council. maile 3_0_0
