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
27 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 34

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 34

Expert Comment

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

Sara
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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