title: Setting a class property on a long running thread
body: <p>I am populating some class properties,</p>
  
  <p>One of them involves serializing an Entity structure to a byte[] this takes some time so I wanted to do it in a thread. </p>
  
  <p>The value never gets set as I assume the class and thread are now out of scope.</p>
  
  <p>The code is below, any ideas would be appreciated</p>
  
  <pre><code>   public class classA
  {
      public void DoSomething()
      {
          var classC = new ClassB().DoSomethingElse();
  
          //SAVE CLASS c to database
          var serialized = classC.GetSerializedDataTable(); // is always null unless i take out the task from class c
      }
  }
  
  public class ClassB
  {
      public ClassC DoSomethingElse()
      {
          var classC = new ClassC();
  
          classC.DataTableValue = new DataTable();
          classC.SerializeToByteArray();
          return classC;
      }
  }
  
  public class ClassC
  {
      public DataTable DataTableValue { get; set; }
      private byte[] serializedData;
  
  
      public void SerializedDataTable()
      {
          new Task(() =&gt; this.serializedData = this.DataTableValue.SerializeToByteArray()).Start();
      }
  
  
      public byte[] GetSerializedDataTable()
      {
          return this.serializedData;
      }
  
  }
  </code></pre>