Avatar of Inam Alvi
Inam Alvi
 asked on

Need help with VB.net application. Sometime, unable to get the UI/Main thread when trying to check with invoke

Hi
I have a multi threading application, in which I am trying to use UI/Main thread to display data.
Here is what I am doing
1. I am getting quote from an API in a thread (each time a new thread is created)
2. I am going to main thread using  "If Me.InvokeRequired"
3. Display information on screen
4. Create a new thread for further processing

I can further explain this with code.
I am also getting the error "A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll"

I am unable to find why I am not able to get UI thread though I am using the following code to check the UI. It some time works and some time it does not work. Some time it goes to UI thread with invoke and sometime it does take the condition and comes to display function with worker thread.

The code is as follow (This is a cut down version)

If Me.InvokeRequired Then
           Dim d As New SetQuoteTempCallback(AddressOf SetQuoteTemp)
            Me.BeginInvoke(d, New Object() {[symbol_id], [bidprice], [askprice]})
Else
           displaySymbolInfoOnChart(symbol_id, bidprice, askprice)
end if
C#Visual Basic.NET

Avatar of undefined
Last Comment
sarabande

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sarabande

The question was abandoned without further response but has a proved solution.

Sara
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck