title: Threading in XMLSerializer
body: <p>How is it possible to extend the following code to be executed in a seperate thread?</p>
  
  <p>The methods calling save/load:</p>
  
  <pre><code>    private void Save()
      {
          ClassDiagram diagram = new ClassDiagram();
          diagram.ClassDatas = ClassDatas.ToList();
          diagram.Connectors = Connectors.ToList();
  
          String filePathAndName = GetSaveFilePathAndName();
          saveLoadSerialization.Save(filePathAndName, diagram);
      }
  
      private void Open()
      {
          String filePathAndName = GetOpenFilePathAndName();
  
          ClassDiagram diagram = saveLoadSerialization.Load&lt;ClassDiagram&gt;(filePathAndName);
          ClassDatas = new ObservableCollection&lt;ClassData&gt;(diagram.ClassDatas);
          Connectors = new ObservableCollection&lt;Connector&gt;(diagram.Connectors);
          Connectors.ToList().ForEach(c =&gt; { c.From = ClassDatas.Single(cd =&gt; cd.Number == c.FromID); c.To = ClassDatas.Single(cd =&gt; cd.Number == c.ToID); });
  
          RaisePropertyChanged("ClassDatas");
          RaisePropertyChanged("Connectors");
      } 
  </code></pre>
  
  <p>The Save/Load XMLSerializer code looks like this - is the best approach an asynchronous thread?</p>
  
  <pre><code>    public void Save&lt;T&gt;(String filePathAndName, T data)
      {
          try
          {
              using (FileStream file = File.Create(filePathAndName))
              {
                  XmlSerializer serializer = new XmlSerializer(typeof(T));
                  serializer.Serialize(file, data);
              }
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
      }
  
      public T Load&lt;T&gt;(string filePathAndName)
      {
          try
          {
              using (FileStream file = File.OpenRead(filePathAndName))
              {
                  XmlSerializer serializer = new XmlSerializer(typeof(T));
                  return (T)serializer.Deserialize(file);
              }
          }
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
  
          return default(T);
      }
  </code></pre>