.NET Framework Bookmark and Share   
 index > .NET Base Class Library > How to solve this Invoke and message queue issue?
 

How to solve this Invoke and message queue issue?

Hi

I am creating a search application in .net framework 1.1. The search is controlled by a button (similar to file search operation of windows). Actual search operartion, i.e. getting data from database, is executed on another thread, say SearchThread.After getting the data, SearchThreadhas to display the searched data. The ListView that is used to display the searched data is created on the UI thread (i.e. main thread), and not on the SearchThread.So to have thread safe method calls, SearchThread uses InvokeRequired and Invoke to pass the displaying of search data to the UI thread. Then UI thread starts executing the method to display the data received from SearchThread. The problem I am facing is that, since the display of search data is running on UI thread (and also it is time taking process because of bulk data), any other events triggered on the UI thread dont get processed until the current displaying process is over. This is because the events get posted to the message queue and cannot be processed until search data display has been completed. But because of this for any control that I click on UI like Stop button or any search criteria selection button, event dont get executed immediately. I need to correct this behavior of my search application.

I need help from anyone to fix this issue. Probably I need some mechanism to execute the events in UI thread (on an emergency basis to ignore any currently running heavy processing of the UI thread). Or anything else....

Please help!

Chaitanya22
You diagnosed this correctly, you are calling (Begin)Invoke too often. The message loop doesn't get around to doing its normal stuff if you call it more than about 1000 times per second. It is wasted effort, the human eye can't tell the difference past 20 times per second. Collect the results in an ArrayList to reduce the rate.

Hans Passant.
nobugz
Why don't you split the task of "displaying data" into several (or many) parts?
Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
Vitaliy Liptchinsky
You diagnosed this correctly, you are calling (Begin)Invoke too often. The message loop doesn't get around to doing its normal stuff if you call it more than about 1000 times per second. It is wasted effort, the human eye can't tell the difference past 20 times per second. Collect the results in an ArrayList to reduce the rate.

Hans Passant.
nobugz
Hi Chaitanya22,
Are those replies helpful for the question? or you got another issue?

Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.
eryang

You can use google to search for other answers

Custom Search

More Threads

• vb.net
• How to Create Activex control
• Properties within a class library
• Confusion with PageSettings for a PageSetupDialog
• Overload error message??
• reflection - CustomAttributeBuilder
• SID in vb.net 2003
• Determine Special Folder Names & Icons
• Store DataTable in custom config section
• Regular expression to replace comma for a csv file import