title: .Net C# Microsoft.Office.Interop.Excel ListObject refresh datasource asynchronously
body: <p>I have a messaging application set up in C# and will add the messages received asynchronously into a list. I am using only the Microsoft.Office.Interop.Excel namespace and not VSTO extensions thus faces a problem with the listobject.</p>
  
  <p>What I want to do is to create a listobject using the method below and use a timer object to write to excel spreadsheet.</p>
  
  <pre><code>public static ListObject AddListObject()
      {
          oXL = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
  
          oWB = oXL.Workbooks.get_Item(1);
          oSheet = (Excel.Worksheet)oWB.ActiveSheet;
  
          activeRow = oXL.ActiveCell.Row;
  
          //content
          oSheet.Cells[activeRow , 1] = Store[0].name;
          oSheet.Cells[activeRow , 2] = Store[0].address;
          oSheet.Cells[activeRow , 3] = Store[0].number;
          oSheet.Cells[activeRow , 4] = Store[0].dob;
  
          Excel.ListObject listObject1 = oSheet.ListObjects.Add(
              Excel.XlListObjectSourceType.xlSrcRange, oXL.ActiveCell.CurrentRegion, false,
              Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, Type.Missing);
          listObject1.TableStyle = "TableStyleLight9";
  
  
  
          oXL.Visible = true;
          oXL.UserControl = false;
  
          return listObject1;
  
  
      }
  </code></pre>
  
  <p>In the main program, after starting the messaging portion, I will get the listobject and pass it to the timer to update the spreadsheet.</p>
  
  <pre><code>listobject1 = AddListObject();
  timer = new Timer(DoSomething, listobject1, 0, 1000);
  </code></pre>
  
  <p>How do I do that when the timer object calls the DoSomething method every second?</p>
  
  <pre><code>public void DoSomething(ListObject obj)
      { 
          //refresh listobject and write and update to spreadsheet every second
  
      }
  </code></pre>
  
  <p>In VSTO, I will do the following:</p>
  
  <pre><code>listobject1 = AddListObject();
  listobject1.DataSource=Store;
  listobject1.AutSetDataBoundColumnHeaders=true;
  timer = new Timer(DoSomething, listobject1, 0, 1000);
  
  public void DoSomething(object state)
      { 
          //refresh listobject and write and update to spreadsheet every second
          ListObject lbo = (ListObject)state;
          lbo.RefreshDataRows();
  
      }
  </code></pre>
  
  <p>How do I do the following without VSTO extensions?</p>