Unable to set error provider in threading

133 Views Asked by At

I have been using errorprovider in VB.Net windows form, which was working fine. How ever I noticed, if I try to set errorprovider seterror method in procedure that was called via threading, the error provider doesn't work.

Is there something I m missing while starting the thread?

My Code:

Dim thrdd1 As New Thread(AddressOf random_procedure)
thrdd1.IsBackground = True
thrdd1.Start()

Privavte Sub random_procedure()

    *do some events*

    seterrorprovider()

End Sub

Private sub seterrorprovider()

    errorpro1.seterror(textbox1,"Unable to load")

End Sub
2

There are 2 best solutions below

1
yangfang On
Public Sub New()

    ' This call is required by the designer。
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call。
    CheckForIllegalCrossThreadCalls = False

End Sub

Add this Code in your UI form ,maybe solve your problem.

0
Suraj Singh On

Found the issue, it was just another illegalcrossthreadcalls. Wasn't able to track it because I have set it to false in formload. Made a sub with invoke to change text of main UI thread. Thanks to anyone who tried helping