Skip to content

(net35) System.Threading polyfill dependency incorrectly flows SynchronizationContext #12

@jnm2

Description

@jnm2

For reference, this demonstrates the bug: https://github.com/jnm2/AsyncBridge/compare/sync_context_flow_bug

This differs from the .NET Framework 4.5 behavior. Example of what can go wrong:

// UI thread
await Task.Run(async () =>
{
    // Thread pool thread
    DoCPUIntensiveWork();
    await DoIOBoundWorkAsync();
    // PROBLEM: the await resumes on the UI thread, not a thread pool thread!
    DoCPUIntensiveWork(); // Ends up blocking the UI thread
});

The workaround is to await DoIOBoundWorkAsync().ConfigureAwait(false). (Once v0.3.0 is out with the fix for #7!) To be clear, ConfigureAwait(false) is better code, but it should still not be necessary.

Looks like another easy fix. The problem is, the source code for TaskParallelLibrary 1.0.2856 is not on the internet as far as I can tell. The nupkg and binaries are first committed to this repo in f97269a and had been downloaded from https://www.nuget.org/packages/rx-core/1.0.2856. I've scoured https://rx.codeplex.com/ and https://github.com/Reactive-Extensions/Rx.NET and am pretty sure they do not contain the source of System.Threading.dll from TaskParallelLibrary.

At this point it seems likely that creating a fresh net47-net35 or perhaps corefx/net35 shim from scratch in a single DLL would be cleanest.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions