【发布时间】:2012-08-20 05:42:30
【问题描述】:
我使用 C# .net 4.0 并且看不到任何可能的方法,但也许你知道吗? :)
我以这种方式进行序列化:
public static void SaveCollection<T>(string file_name, T list)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = null;
try
{
fs = new FileStream(Application.StartupPath + "/" + file_name, FileMode.Create);
bf.Serialize(fs, list);
fs.Flush();
fs.Close();
}
catch (Exception exc)
{
if (fs != null)
fs.Close();
string msg = "Unable to save collection {0}\nThe error is {1}";
MessageBox.Show(Form1.ActiveForm, string.Format(msg, file_name, exc.Message));
}
}
【问题讨论】:
-
哇。您正在序列化如此大的东西,以至于您实际上可以在挂钟上计时?你在做 XML 序列化吗?
-
嗯是的,我的一些可序列化的东西可能需要长达 1 分钟,这是二进制序列化 :) 只是很多对象......
-
序列化后你的对象有多大? (平均?)
-
9Mbs,序列化大约需要 10 秒,而集合包含 1066 个不同大小的对象。另一个例子 - 19 Mbs 和大约 30 秒的序列化,而集合有更多的对象
-
这没有任何意义。那是小。你在做 BinaryFormatter.Serialize() 以外的事情吗?
标签: c# .net serialization progress-bar binaryformatter