flashkid10
Member
- Joined
- Dec 9, 2016
- Messages
- 16
- Programming Experience
- Beginner
How do I attaching a XmlSerializer to Progress Bar (called SaveBar)? the Serializer is called from a background worker
public class TestObject
{
public int OneValue { get; set; }
public int TwoValue { get; set; }
}
TestObject test = new TestObject { OneValue = 5, TwoValue = 4 };
private void SaveB_Click(object sender, EventArgs e) //This is the button event that starts everything
{
SaveBar.Maximum = 100;
SaveBar.Step = 1;
SaveBar.Value = 0;
SaveWorker.RunWorkerAsync(test);
}
public static void SaveData(List<Item> obj, string filename) // this is the Serializer
{
XmlSerializer sr = new XmlSerializer(obj.GetType());
TextWriter writer = new StreamWriter(filename);
sr.Serialize(writer, obj);
writer.Close();
}
private void SaveWorker_DoWork(object sender, DoWorkEventArgs e) //This is the backgound worker
{
TestObject argumentTest = e.Argument as TestObject;
Thread.Sleep(1000);
argumentTest.OneValue = 6;
argumentTest.TwoValue = 3;
e.Result = argumentTest;
Xml.SaveData(Item.MainList, "AniListData.xml");
}
public class TestObject
{
public int OneValue { get; set; }
public int TwoValue { get; set; }
}
TestObject test = new TestObject { OneValue = 5, TwoValue = 4 };
private void SaveB_Click(object sender, EventArgs e) //This is the button event that starts everything
{
SaveBar.Maximum = 100;
SaveBar.Step = 1;
SaveBar.Value = 0;
SaveWorker.RunWorkerAsync(test);
}
public static void SaveData(List<Item> obj, string filename) // this is the Serializer
{
XmlSerializer sr = new XmlSerializer(obj.GetType());
TextWriter writer = new StreamWriter(filename);
sr.Serialize(writer, obj);
writer.Close();
}
private void SaveWorker_DoWork(object sender, DoWorkEventArgs e) //This is the backgound worker
{
TestObject argumentTest = e.Argument as TestObject;
Thread.Sleep(1000);
argumentTest.OneValue = 6;
argumentTest.TwoValue = 3;
e.Result = argumentTest;
Xml.SaveData(Item.MainList, "AniListData.xml");
}