In one of my projects I use a series of asynchronous web service calls from a console app running as a scheduled job to create XML data files from a Sharepoint Server document library through the Microsoft OLEDB Provider for Internet Publishing (MSDAIPP).
The XML data files become an intelligent middle data layer and are integrated with SQL Server data to provide some pretty cool functionality. I need to put an article together on it... Anyway, the console app which generates the XML data files spits out a log file with times for completing the various XML data file creation tasks. Like so:
Log Entry : 8:21:34 AM 8/27/2003 : 22 seconds : Created Folder Workfile
Log Entry : 8:23:48 AM 8/27/2003 : 133 seconds : Created All Files Gold
Log Entry : 8:24:16 AM 8/27/2003 : 28 seconds : Created Search File
Log Entry : 8:24:31 AM 8/27/2003 : 14 seconds : Created PID File
Log Entry : 8:24:51 AM 8/27/2003 : 20 seconds : Created PID Project Folder File
The second totals just weren't correct and I let the error persist for a week or so while I attended to more important tasks. The log file was just for my personal monitoring needs, after all. When I had a minute I went back to see what I was doing wrong. The original code was:
System.TimeSpan TotalTime = System.DateTime.Now - StartTime;
Double secs = TotalTime.Seconds;
Log(secs.ToString(), "Created Folder Workfile");
After a little digging into the TimeSpan structure, I read that .Seconds was "the second component of this instance, between 0 and 59" where .TotalSeconds was "the total number of seconds represented by this instance." So
Double secs = TotalTime.TotalSeconds;
yielded the correct second count, along with some ToString()... formatting to remove the fractional digits, providing a clean and correct output.
I realize this is an inconsequential incident, but its one of those cool finds that reinforces the wealth of class members and properties available in VS.NET with a little digging.