Solved

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

Posted on 2016-09-14
2
13 Views
Last Modified: 2016-10-04
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
0
Comment
Question by:Inam Alvi
  • 2
2 Comments
 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points (awarded by participants)
ID: 41799254
generally, if you call from a worker thread to ui thread, you have to use windows messaging. you never may call functions of a different thread context directly.

so the general concept is to create an object where the results to display were stored. then post a  user message to the main thread passing a handle to the result object as argument. the main thread would have an event handler for the message and displays the results.

Sara
0
 
LVL 32

Expert Comment

by:sarabande
ID: 41827718
The question was abandoned without further response but has a proved solution.

Sara
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now