locked
Question about UI Thread Invoking RRS feed

  • Question

  •  

    Hello everyone.
    I'm building a chat client application, and I'm trying to follow the Model-View-Controller pattern as strictly as I can.
    I'm stuck at creating a new chat window when a message comes in. The problem is, when the controller gets the message, it needs to tell view to create a new form. It is a well-known taboo to manage UI objects on a non-UI thread, so I need to create a new Form on a UI Thread. However, there's no UI control object I can BeginInvoke that call on.
    How do i safely create a Form from a different non-UI thread when there's no other form to BeginInvoke from?
    Monday, August 13, 2007 2:50 PM

Answers

  • Does it violate your design to give the class spawning the form a reference to an object that you can invoke against? There's precedent for this in a couple places in the Framework, look at the SynchronizingObject property of System.Timers.Timer. System.Windows.Forms.Control implements System.ComponentModel.ISynchronizeInvoke, so any GUI object is fair game.
    Monday, August 13, 2007 3:04 PM