Attaching a XmlSerializer to Progress Bar from a Background worker

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");
}














 
You don't attach anything to a ProgressBar. A ProgressBar is simply a visual representation of a proportion. It's up to you to provide the proportion for it to represent. If you can't measure the progress of an operation then you can't represent it using a ProgressBar. Can you measure the progress of a call to XmlSerializer.Serialize? I don't think so, so there's nothing for your ProgressBar to represent. The best you can do in such cases is set the Style to Marquee to indicate that something is happening but not how far along that something is.
 
By the way, please don't make your posted code snippets hard to read like that. Post them as plain text between specific code formatting tags, i.e.

[xcode=c#]your code here[/xcode]

or

[code]your code here[/code]
 
Back
Top Bottom