You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Service registration: AddSingleton<IMessenger>(WeakReferenceMessenger.Default)
Message registration: _messenger.Register<AsyncRelayCommandPageViewModel, TestAsyncMessage1>(this, static (r, m) => m.Reply(r.Action1(m)));
Behavour:
Case1:
If Action1 is of type Task<T> and we do following:
stringresponse=await_messenger.Send<TestAsyncMessage1>(new());privateasyncTask<string>Action1(TestAsyncMessage1msg){awaitTask.Delay(TimeSpan.FromSeconds(5));Trace.WriteLine("Action1 process complete");return"hello";}
the response is of type string and contains the value hello.
Case2:
However, if Action1 is of type Task and we do following:
Taskresponse=await_messenger.Send<TestAsyncMessage1>(new());privateasyncTaskAction1(TestAsyncMessage1msg){awaitTask.Delay(TimeSpan.FromSeconds(5));Trace.WriteLine("Action1 process complete");}
the response is of type Task.
Issue:
In Case1 does the await actually awaits the internal task (Action1) and return the value of the task, in this case the string hello.
In Case2 does the await awaits that the message is sent, but not the internal task (Action1).
So if we want the same behaviour for Case2, where we want the internal task to be completed, we have to do something like:
Description
Depening on the return type, we have different behavour.
Is this wanted? Would it make sense to add something like ProcessTask to the library to extend the functionality?
Regression
No response
Steps to reproduce
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.12.4
CommunityToolkit.Mvvm
Version 8.2.2
Expected behavior
See description of bug.
Screenshots
No response
IDE and version
VS 2022
IDE version
Version 17.12.4
Nuget packages
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.2.2
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item
The text was updated successfully, but these errors were encountered:
After more investigation, we have decided that we are using async messages the wrong way.
However, we still belive that the difference in behavior when a Task vs Task<string> are the return type should be investigated or clarified.
Describe the bug
Service registration:
AddSingleton<IMessenger>(WeakReferenceMessenger.Default)
Message registration:
_messenger.Register<AsyncRelayCommandPageViewModel, TestAsyncMessage1>(this, static (r, m) => m.Reply(r.Action1(m)));
Behavour:
Case1:
If
Action1
is of typeTask<T>
and we do following:the response is of type
string
and contains the valuehello
.Case2:
However, if
Action1
is of typeTask
and we do following:the response is of type
Task
.Issue:
In Case1 does the
await
actually awaits the internal task (Action1) and return the value of the task, in this case the stringhello
.In Case2 does the
await
awaits that the message is sent, but not the internal task (Action1).So if we want the same behaviour for Case2, where we want the internal task to be completed, we have to do something like:
We are now implementation our own solution, using an extension method:
Making it possible to do following:
Description
Depening on the return type, we have different behavour.
Is this wanted? Would it make sense to add something like
ProcessTask
to the library to extend the functionality?Regression
No response
Steps to reproduce
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.12.4
CommunityToolkit.Mvvm
Version 8.2.2
Expected behavior
See description of bug.
Screenshots
No response
IDE and version
VS 2022
IDE version
Version 17.12.4
Nuget packages
Nuget package version(s)
8.2.2
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item
The text was updated successfully, but these errors were encountered: