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
26 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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2015 auto inserted code 12 86
FTP recursive download files 5 23
Using the .NET JSON Serializer to create a single string 6 52
How does this modal gets closed? 6 38
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 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