Skip to content

Added Async support #9

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

maca88
Copy link

@maca88 maca88 commented Apr 13, 2016

Async can be disabled by adding SYNC_ONLY flag.

@staxmanade
Copy link
Owner

What is SYNC_ONY? (Just curious, should it be SYNC_ONLY)?

@maca88
Copy link
Author

maca88 commented Apr 14, 2016

My bad. I replaced SYNC_ONLY flag with ASYNC and added UNWRAP_EX flag to avoid breaking changes. In addition I tweaked the test project so that can be tested for each flag or combination of them.

@staxmanade
Copy link
Owner

@JakeGinnivan Would you mind giving this PR a once over? There are a lot of changes. From initial glance, it looks pretty good. But I haven't written C# in a while and am not up to date on the various platform changes...

@ucswift
Copy link

ucswift commented Apr 17, 2016

@staxmanade I'll take a look as well latter today, as we use it in @Resgrid.

public class AsyncSample
{
public static void Run()
{
var config = new EventAggregator.Config
{
// Make the marshaler run in the background thread
DefaultThreadMarshaler = action => Task.Factory.StartNew(action),
DefaultThreadAsyncMarshaler = async action => await Task.Factory.StartNew(action),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the async/await pair. Task.Factory.StartNew will never throw (and the only difference async/await will make is that Run() will end up in the call stack of an exception)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed back and the marshal param removed from the async send message overloads

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the async/await pair. The DefaultThreadMarshaler is still there I just added the async one as Action<> can not be awaited.

@JakeGinnivan
Copy link
Contributor

@staxmanade I haven't used this project for a while, so some of the comments might be off (is this a content nuget package or a distributed binary for instance?).

@maca88 the main thing is to add .ConfigureAwait(false) everywhere in the library which uses await. And remove that .Wait() because it will cause someone a deadlock when they run SendMessageAsync and in their message handler they have an await which will capture the UI sync context, but the .Wait() has blocked the UI thread. You then deadlock because the .Wait() needs the task to complete but the scheduled continuation is waiting to run on the blocked UI thread.

@ucswift
Copy link

ucswift commented Apr 18, 2016

@JakeGinnivan Nice comments on the PR. .ConfigureAwait(false) is a biggie. Nuget distribution is content (drops a .cs file into an Events folder). Really good catch on the Wait() as well.

@maca88 Is there anyway to stand up the Async methods alongside the current ones? Preprocessor directives are sometimes necessary, but tend to complicate the API surface when being used to hide implementations. Really depends on where the breaking changes are.

…5.2, added stack trace preservation for .net profile client, added configure await for all awaits, replaced wait with configure await.
@maca88
Copy link
Author

maca88 commented Apr 18, 2016

@ucswift I wrapped all async stuff into ASYNC directive in order to support .NET 4 as well. Also the UNWRAP_EX was added in order to not having any breaking changes. If you don't care about supporting .NET 4 I can remove the ASYNC directive.

@ucswift
Copy link

ucswift commented Apr 26, 2016

@maca88 That makes more sense, using the directives to support .Net 4. I don't know where the value lies in support 4.0 verses bumping support to say 4.5, guess that would be an @staxmanade decision.

@staxmanade
Copy link
Owner

Hey All

Unfortunately I haven't used this library since StatLight 😢 . I also have been a bit out of touch with all of the various .Net ports/versions/etc.

So if I can get a 👍 from at least @ucswift or @JakeGinnivan on this PR - then I'll merge it and re-figure out how to publish it to NuGet...

@maca88 - thanks for you're hard work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants