Bug 38599 - Regression: SynchronizationContext.Current returns wrong value in delegate run by SynchronizationContext.Send.
Summary: Regression: SynchronizationContext.Current returns wrong value in delegate ru...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-02-09 22:24 UTC by Tom Hindle
Modified: 2016-02-22 15:36 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case showing regression. (1.11 KB, text/x-csharp)
2016-02-09 22:24 UTC, Tom Hindle
Details
Another example showing bug using System.Timers.Timer with SynchronizingObject set. (671 bytes, text/x-csharp)
2016-02-10 18:11 UTC, Tom Hindle
Details

Description Tom Hindle 2016-02-09 22:24:43 UTC
Created attachment 14973 [details]
Test case showing regression.

See attached test program:

SynchronizationContext uiSyncContext = ....;
uiSyncContext.Send((state) =>
{
  // This should be true.
  // SynchronizationContext.Current == uiSyncContext
  // In mono 4.2.1 SynchronizationContext.Current returns null.
};

The following is output of test program running on various systems.
Note for mono 4.2.1 the last line doesn't return the expected result.

Output on .net:

Runing on UI thread context = 'System.Windows.Forms.WindowsFormsSynchronizationContext' expected: WindowsFormsSynchronizationContext
Thread running context = '' expected: (null or NOT WindowsFormsSynchronizationContext)
Running on UI thread context = 'System.Windows.Forms.WindowsFormsSynchronizationContext' expected: WindowsFormsSynchronizationContext

Output on mono 3.2.8:

Runing on UI thread context = 'System.Windows.Forms.WindowsFormsSynchronizationContext' expected: WindowsFormsSynchronizationContext
Thread running context = '' expected: (null or NOT WindowsFormsSynchronizationContext)
Running on UI thread context = 'System.Windows.Forms.WindowsFormsSynchronizationContext' expected: WindowsFormsSynchronizationContext


Output on mono 4.2.1

Runing on UI thread context = 'System.Windows.Forms.WindowsFormsSynchronizationContext' expected: WindowsFormsSynchronizationContext
Thread running context = '' expected: (null or NOT WindowsFormsSynchronizationContext)
Running on UI thread context = '' expected: WindowsFormsSynchronizationContext
Comment 1 Tom Hindle 2016-02-10 18:11:21 UTC
Created attachment 14988 [details]
Another example showing bug using System.Timers.Timer with SynchronizingObject set.

f
Comment 2 Marek Safar 2016-02-10 19:30:57 UTC
Fixed in master and Mono 4.3.2
Comment 3 Tom Hindle 2016-02-22 15:36:19 UTC
commit for fix was d5a93b13bf47508173e512178f32abd1e8411b98.

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.


Create a new report for Bug 38599 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: