Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatcher thread in MVVM application is blocking the tests. #2736

Open
chandu07 opened this issue Feb 2, 2024 · 0 comments
Open

Dispatcher thread in MVVM application is blocking the tests. #2736

chandu07 opened this issue Feb 2, 2024 · 0 comments
Labels

Comments

@chandu07
Copy link

chandu07 commented Feb 2, 2024

SpecFlow Version

3.9.22

Which test runner are you using?

xUnit

Test Runner Version Number

2.4.2

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

No response

Issue Description

I have na MVVM application that has various ViewModels for different aspects of the project. In the MainWindowViewModel, I have a ProjectViewModel that will need to be instantiated based on the project that is open. As the projects are heavy and needs deserialization to load everytime, I am running the OpenProject method as an async task.

`Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;

public async Task OpenProject()
{
dataCard = await Task.Factory.StartNew(() => _pManager.Deserialize());
_dispatcher.Invoke((Action)delegate
{
_pManager.BeginNewScope(dataCard);
});
}`

This async OpenProject task has a part where we start the scope of the project in the main UI thread (_dispatcher) instead of the background task thread. Everything works fine when I am running the application. However, when running the OpenProject method with Specflow for acceptance testing, it goes into a loop after _dispatcher.Invoke. Could you please suggest what could be going wrong here?

Steps to Reproduce

Create an async task and run a dispatcher.invoke within it, like below.

'Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;

public async Task OpenProject()
{
dataCard = await Task.Factory.StartNew(() => some_method);
_dispatcher.Invoke((Action)delegate
{
some_command;
});
}'

Link to Repro Project

No response

@chandu07 chandu07 added the Bug label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant