RadMessageBoxForm and Ctrl+C in MTA Thread

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    22 posts
    Member since:
    Oct 2012

    Posted 18 Mar 2013 Link to this post


    When I create and show RadMessageBoxForm from System.Threading.ApartmentState.MTA thread I cannot copy text from it by Ctrl+C key pressing.
    I got ThreadStateException:
    Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
  2. Anton
    Anton avatar
    167 posts

    Posted 21 Mar 2013 Link to this post

    Hi Thomas,

    Thank you for the writing.

    The RadMessageBoxForm uses the Clipboard that requires an STA. So the solution in this case is to set the ApartmentState of your thread to be STA. For example:                              
        ThreadStart job2 = new ThreadStart(SecondThreadJob);
        Thread thread2 = new Thread(job2);
    private void SecondThreadJob()
        RadMessageBoxForm form = new RadMessageBoxForm();
        form.DialogResult = DialogResult.No;
        form.RightToLeft = RightToLeft.No;
        form.MessageText = "thread2";
        form.StartPosition = FormStartPosition.CenterParent;
        form.MessageIcon = null;
        form.ButtonsConfiguration = MessageBoxButtons.YesNo;
        form.DefaultButton = MessageBoxDefaultButton.Button1;

    There's lots of code in Windows that requires an STA. Notable examples are the Clipboard, Drag & Drop and the shell dialogs (like OpenFileDialog). The UI thread of a WPF or Windows Forms project should always be STA, as does any thread that creates a window.

    I hope this helps. Let me know if you have additional questions.

    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top