Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# protobuf网络线程安全吗?_C#_Protobuf Net - Fatal编程技术网

C# protobuf网络线程安全吗?

C# protobuf网络线程安全吗?,c#,protobuf-net,C#,Protobuf Net,我注意到,当我在多线程上下文中使用protobuf net时,它往往会间歇性失败,并出现以下错误: System.TimeoutException: Timeout while inspecting metadata; this may indicate a deadlock. This can often be avoided by preparing necessary serializers during application initialization, rather than a

我注意到,当我在多线程上下文中使用protobuf net时,它往往会间歇性失败,并出现以下错误:

System.TimeoutException: Timeout while inspecting metadata; this may indicate a deadlock. 
This can often be avoided by preparing necessary serializers during application initialization, rather than allowing multiple threads to perform the initial metadata inspection
但是,如果我在第一次序列化特定类型时锁定了对protobuf网络序列化程序的访问,它将正常工作


protobuf net是线程安全的,还是这只是一个bug?

protobuf的元数据检查不是线程安全的。这个错误“很少见”,但在并行执行的大型序列化中经常发生。我在我的项目中遇到了这个错误,我序列化了大约7000万个对象。您可以通过在序列化之前生成元数据来修复它:

Serializer.PrepareSerializer<YourCustomType1>();
Serializer.PrepareSerializer<YourCustomType2>();

你所描述的是非常罕见的;如果你有一个复制这个的对象模型(即使只有百分之一的时间),我想看看它,看看什么是“向上的”
// Initialize Protobuf Serializer for 5 minutes of wait in the case of long-waiting locks
RuntimeTypeModel.Default.MetadataTimeoutMilliseconds = 300000;