Answered Modeling Transactions from a Background Thread

  • Tuesday, July 24, 2012 12:09 PM
     
     

    We have a long running XML import operation, so we do it in a background thread.  Makes sense.  We read in the file, and use it to populate our model.

    But we are sometimes seeing a cross-thread exception thrown.  In the past, I have seen this when doing the no-no of directly trying to update a Winform control from a background thread without using invoke, or something along those lines.

    So, I suspect this is happening to us because we are doing modeling transaction commits in the background thread (which updates the GUI).  My suspicion is that this is not thread safe, and also a no-no.  This article:  http://msdn.microsoft.com/en-us/library/ee941659.aspx (which talks to UML modeling) seems to confirm my suspicions here.  As I recall, UML modeling is based on DSL tools, right?

    So, the logical fix would seem to be to do the modeling transactions only in the UI thread?

All Replies

  • Wednesday, July 25, 2012 8:21 AM
     
     Answered

    Yes, unfortunately, dsl tools mechanisms are not thread safe. So, you have to set up additional logic to support parallel action on your model.

    UML modeling is well based on DSL Tools.

    And you're right, a workaround is to use (force) UI Thread to interact with your model. Specially, if you use in parallel ui data binding mechanism.

    Pascal


    blog.mexedge.com

    • Marked As Answer by Bridges99 Wednesday, July 25, 2012 12:07 PM
    •