locked
vb.net clipboard.settext(textbox1.text) not working backgroundworker RRS feed

  • Question

  • I have a little app that I want to capture textbox text to clipboard.  within UI or button simple  clipboard.settext(textbox1.text) works but with backgroundworker it does not.   Thoughts?  

    Exception thrown: 'System.Threading.ThreadStateException' in System.Windows.Forms.dll

    Private Sub TbResponseWindow_TextChanged(sender As Object, e As EventArgs) Handles tbResponseWindow.TextChanged
    
            If tbResponseWindow.Text.Contains("lb") Then
                Debug.WriteLine(tbResponseWindow.Text)
                Clipboard.SetText(tbResponseWindow.Text)
            End If
    
        End Sub



     

    Work Smarter Not Harder

    Tuesday, May 7, 2019 3:50 PM

Answers

  • Hello,

    Please try this pattern

    BeginInvoke(
        Sub()
            Clipboard.SetText(tbResponseWindow.Text)
        End Sub)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by jimbrown.net Tuesday, May 7, 2019 4:09 PM
    Tuesday, May 7, 2019 4:02 PM

All replies

  • Hello,

    Please try this pattern

    BeginInvoke(
        Sub()
            Clipboard.SetText(tbResponseWindow.Text)
        End Sub)


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by jimbrown.net Tuesday, May 7, 2019 4:09 PM
    Tuesday, May 7, 2019 4:02 PM
  • Thank you,  that worked.  

    Work Smarter Not Harder

    Tuesday, May 7, 2019 4:09 PM