小编Mag*_*his的帖子

计算运营的ETA的最佳方法是什么?

我正在寻找使用线性进度信息计算操作的ETA(IE:文件下载)的最佳方法.

让我们说我有以下方法被调用:

void ReportProgress(double position, double total)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我有几个想法:

  • 计算一段时间内的进度(如最后10秒),并将该速度用作操作的平均速度
  • 保留一组已报告的最后x个进度,计算每个增量的速度并使用平均值

math progress time-estimation

14
推荐指数
4
解决办法
1万
查看次数

Protobuf-Net 回退到 ISerialized 机制

出于性能原因,我在反序列化保存数据的程序集与序列化数据的程序集相同的情况下使用protobuf-net 。

我序列化的大多数类型都是用ProtoContractProtoMember属性标记的简单合约,但有时我必须序列化具有许多子类的奇怪对象(即:Exception)。

我使用经典的 ISerialized 机制通过以下解决方法使其工作。

我对 protobuf-net 很陌生,想知道这是否是一个好主意以及是否有更好/标准的方法来做到这一点。

我的解决方法:

我定义了一个实现经典序列化的通用代理

[ProtoContract]
class BinarySerializationSurrogate<T>
{
    [ProtoMember(1)]
    byte[] objectData = null;

    public static implicit operator T(BinarySerializationSurrogate<T> surrogate)
    {
        T ret = default(T);
        if (surrogate == null)
            return ret;

        var serializer = new BinaryFormatter();
        using (var serializedStream = new MemoryStream(surrogate.objectData))
            ret = (T)serializer.Deserialize(serializedStream);

        return ret;
    }

    public static implicit operator BinarySerializationSurrogate<T>(T obj)
    {
        if (obj == null)
            return null;

        var ret = new BinarySerializationSurrogate<T>();

        var …
Run Code Online (Sandbox Code Playgroud)

c# serialization protobuf-net

5
推荐指数
1
解决办法
727
查看次数