如何解决gRPC IFeatureCollection已被处置对象名称:“集合”
使用我拥有的c#gRPC服务器
IServerStreamWriter<ClientNotification> ClientNotificationStream
发送用户通知
当我尝试致电ClientNotificationStream.WriteAsync(parameters)
时
我有
System.ObjectdisposedException: 'IFeatureCollection has been disposed.
Object name: 'Collection'.'```
IFeatureCollection has been disposed.
Object name: 'Collection'.. Internal Error: StackTrace: at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ThrowContextdisposed()
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.Contextdisposed()
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.Fetch[TFeature](TFeature& cached,Func`2 factory)
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_RequestAborted()
at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.get_CancellationTokenCore()
at Grpc.Core.ServerCallContext.get_CancellationToken()
at Grpc.AspNetCore.Server.Internal.HttpContextStreamWriter`1.WriteAsync(TResponse message)
解决方法
ClientNotificationStream 在我需要执行 WriteAsync() 时被释放。为了修复它,我添加了
WaitHandle.WaitAny(new[] { context.CancellationToken.WaitHandle });
context
是 ServerCallContext
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。