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
19 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 33

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 33

Expert Comment

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

Sara
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

26 Experts available now in Live!

Get 1:1 Help Now