none
WindowsFormsSynchronizationContext Failing to Marshall SendOrPostCallback RRS feed

  • Question

  • Hi All,

    I am experiencing an ArgumentException on Windows 8 PCs when my library code attempts to fire events using the SynchronizationContext's Post method. The message is "Controls created on one thread cannot be parented to a control on a different thread." This is due to the library's client attempting to update the UI in response to the event. This unexpected, since the SynchronizationContext, which is of type WindowsFormsSynchronizationContext in this instance and provided by the library's client, is supposed to marshall the call to the UI thread.

    I've tried searching the forums here for any reports of this and came up empty handed. Am I misunderstanding how this SynchronizationContext is meant to be used?

    N.B., this issue does not occur on Windows 7, but seems to be limited to Windows 8.

    Thanks,

    Joe

    Thursday, February 11, 2016 3:31 PM

All replies

  • Hi sollicita,

    >>I am experiencing an ArgumentException on Windows 8 PCs when my library code attempts to fire events using the SynchronizationContext's Post method

    How did you do that. Could you provide more information about it. What is your project type and could you provide any sample code?

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 12, 2016 2:16 AM
    Moderator
  • In the UserControl's OnLoad method it stores SynchronizationContext.Current in a member variable that is passed to the library's constructor later on. The SynchronizationContext's Post method is used from threads within the library to fire events that are encapsulated in SendOrPostCallback objects. That's it in a nutshell. 

    I'd provide you with sample code that reproduces the issue, but it's not consistently reproducible. I have a workaround that I'll be testing though. It involves creating my own WinFormSyncContext that calls the UserControl's BeginInvoke and Invoke methods in Post and Send respectively.

    Saturday, February 13, 2016 11:03 PM
  • Hi sollicita,

    Kindly post your sample code. It will help us understanding your question.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 15, 2016 7:02 AM
    Moderator