Blazor. Асинхроннй доступ к контексту EF. A second operation started on this context before a previous operation completed

Есть blazor компонент, который имеет кнопку Edit со следующим behind:

    async Task EditUser(User user)
    {
        // Set the selected user
        // as the current user
        objUser = user;
        if (user != null)
        {
            // Is user in administrator role?
            var UserResult = await _userManager.IsInRoleAsync(user, ADMINISTRATION_ROLE);
            if (UserResult)
            {
                CurrentUserRole = ADMINISTRATION_ROLE;
            }
            else
            {
                CurrentUserRole = "Пользователи";
            }

        }
        // Open the Popup
        ShowPopup = true;
    }

Если быстро нажимать несколько раз на кнопку, вылетает Exception:

Error: System.InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.

Как решается данная проблема в ASP или Blazor? Обычно использую какие-нибудь свои репозитории, где каждый раз создаю контекст на любую CRUD новый и тогда таких проблем нет, но в случае с UserManager или SignManager как поступить?


Ответы (0 шт):