Threaded application using DateTime.NOW returns same time always!

Jan 14 2009 5:02 PM

 I have an application that is using a Thread. At the moment I am creating only one Thread and starting it. Within the

thread I am creating an Excel spreadsheet with the run date stamped on it. This Thread has a System.Timers.Timer in it which

executes the method that creates the Excel file. Whenever the timer elapsed event is fired, I create the Spreadsheet and

then insert into a cell DateTime.NOW.
Problem is it seems to return the same time every time it is called! Actually, I believe that DateTime.Now is returning the

time the program was started, not the current tiem. I have tried using a variable to hold the DateTime, I also tried

accessing that variable using the LOCK function but it still returns the same time. Any ideas on why this would occur?

[code] 

 

 private void Form1_Load(object sender, EventArgs e)
        {
  Thread thrdContract = new Thread(new ThreadStart(StartExcelTimer));
                thrdContract.Start();           
          
        }

      
 protected void StartExcelTimer()
        {

            tmrC = new System.Timers.Timer();
            tmrC.Elapsed += new System.Timers.ElapsedEventHandler(tmr_RunExcel);
            tmrC.Interval = 200000;
            tmrC.Enabled = true;
            tmrC.Start();
        }

  void tmr_RunExcel(object sender, System.Timers.ElapsedEventArgs e)
       {
  ExcelClass ex = new ExcelClass();
  ex.CreateExcelDoc();

 }

 


-- Below is the ExcelClass code that is being called

 public void CreateAndExportSpreadSheetExcelApp(DataTable dt, string cHeader,
       ref string cSeedCellAddress, List<XLSColumnProperty> ColList, string cPath, string cRunTm)
        {
            try
            {
              

  -- There is code before this that just creates the Excel file
  -- Below is the code that is causing a problem

               
 
                range = oExcelSheet.get_Range(cRng1, cRng1);
 
  ******** PROBELM DATETIME CODE********

                range.Value2 = "App Version : Version: 1.0, Date: " + DateTime.Now;

                range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
                range = oExcelSheet.get_Range(cRng1, cRng2);
                range.Merge(objbool);

 

                objBook.SaveCopyAs(cPath);

                objBooks.Close();
                objExcel.Quit();


                System.Runtime.InteropServices.Marshal.ReleaseComObject(objBooks);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcelSheets);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcelSheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel);
                objBook = null;
                objBooks = null;
                objExcel = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
 
            }
            catch
            { }

        }

[/code]