I would like to implement an automatic backup function in my software where the main object gets serialized and stored asynchronously on a timed schedule, but do it asynchronously so as to not slow down the main program.
Currently, my serialization/saving function looks like this:
To save any class as XML, I just call from within the class:
So what is the best way to make the Serialize function work the same as it does, but asynchronously?
Currently, my serialization/saving function looks like this:
.net Code:
Public Function Serialize(FileName As String, Obj As Object, XML As Boolean) As Boolean ' Serializes an object. XML = True if XML serializing, otherwise Binary. Returns True if no errors. Dim S As FileStream = Nothing Dim F As Object Serialize = True Try If XML Then F = New Xml.Serialization.XmlSerializer(Obj.GetType) Else F = New BinaryFormatter End If S = New FileStream(FileName, FileMode.Create) F.Serialize(S, Obj) Catch ex As Exception MessageBox.Show("Error Saving '" & ShortenPath(FileName) & "'" & vbNewLine & vbNewLine & ex.Message, "File Save Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) Serialize = False Finally If S IsNot Nothing Then S.Close() End Try End Function
To save any class as XML, I just call from within the class:
.net Code:
Success = Serialize(FileName, Me, True)
So what is the best way to make the Serialize function work the same as it does, but asynchronously?