【问题标题】:Blazor WebAssembly Monitor Threading exceptionBlazor WebAssembly 监控线程异常
【发布时间】:2020-08-13 14:41:45
【问题描述】:

我目前正在开发一个 .NET Standard 2.1 Blazor WebAssembly 托管应用程序。

我的应用程序结构如下所示:

  • BlazorApp.Client(此处发生错误)
  • BlazorApp.Server

我在我的 BlazorApp.Client 项目中使用 Serilog 和 Elasticsearch 接收器。它工作正常,但是当我在 Serilog 上启用 Selflog 并进行调试时,我在浏览器控制台中收到以下错误:

SelfLog.Enable(msg => Debug.WriteLine(msg));

Elasticsearch.Net.UnexpectedElasticsearchClientException:无法等待此运行时的监视器。 ---> System.Threading.SynchronizationLockException: 无法在此运行时等待监视器。

at (wrapper managed-to-native) System.Threading.Monitor.Monitor_wait(object,int)

在 System.Threading.Monitor.ObjWait (System.Boolean exitContext, System.Int32 毫秒超时, System.Object obj) in :0

在 System.Threading.Monitor.Wait (System.Object obj, System.Int32 millisecondsTimeout, System.Boolean exitContext) in :0

这似乎是当前 Blazor WASm 版本中的一个问题:https://github.com/dotnet/aspnetcore/issues/22400

Cannot Wait on monitors 有谁知道,如何在 Blazor WebAssembly 客户端中消除此错误?

【问题讨论】:

  • 我认为目前WASM上的MONO运行时只支持单线程。

标签: c# multithreading blazor webassembly .net-standard-2.1


【解决方案1】:

您无法在 Blazor WebAssembly 中“摆脱”该错误。 WebAssembly 代码(暂时)是单线程的,因此执行 System.Threading.Monitor.Wait(something); 肯定会出现死锁。

框架正确地向您发出此代码不适合 WebAssembly 的信号。

您将不得不摆脱任何需要 Wait() 的代码。

【讨论】:

    猜你喜欢
    • 2021-06-16
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2020-06-26
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多