Re: MVP please help - ShowDialog() very slow



Sorry for being dense, but once the list box is loaded, when I do
ShowDialog() a second or third time, since I am not loading the list box
again, I'm not sure how these loading suggestions will help. The code that
actually adds the items to the list box is only executed once, in the
constructor.

Are you saying that each time I do ShowDialog() that I should reload my
items?

Thanks in advance.
"Chris Sano" <csano@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:e0sX90ygFHA.2644@xxxxxxxxxxxxxxxxxxxxxxx
>
> You should also consider using asynchronous delegates to load your data.
> You can either disable the listbox while the data is loading or show some
> kind of indication that data is loading (let it be a sliding progress bar,
> wait cursor or anything you like).
>
> "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:eHNNTdtgFHA.3220@xxxxxxxxxxxxxxxxxxxxxxx
>> You need to remember that the ListBox control is a wrapper around the old
>> Win32 control and in fact, when data is placed in the ListBox the wrapper
>> updates the underlying control using standard windows messages.
>>
>> This is why the display phase is so time-consuming.
>>
>> You need to consider some other loading scheme. Perhaps load the data in
>> chunks using a timer. that will enable the top of the listbox to display
>> quickly and continue to load while the user is doing other things.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Ramuseco Limited .NET consulting
>> http://www.ramuseco.com
>>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>> http://www.bobpowell.net/tipstricks.htm
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/faqmain.htm
>>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>>
>>
>>
>> "Valerie Hough" <sales@xxxxxxxxxxx> wrote in message
>> news:%23IRfmnngFHA.1412@xxxxxxxxxxxxxxxxxxxxxxx
>>>I don't think that the problem is the actual loading of the list box. I
>>>load it in the constructor of the dialog; it takes less than two seconds
>>>(using ListBox.Items.Add() ). The problem occurs (as near as I can tell)
>>>when the list box switches to visible as part of ShowDialog(). Once the
>>>list box becomes visible, there are no problems, performance (navigating
>>>to records etc.) is just as fast as if there are only 100 items.
>>>
>>> Not to disagree with your conclusion that 50,000 records is too much,
>>> but if so, how many are too many? In the old days (C++ 4 or maybe even
>>> earlier), there used to be a limitation of 32768 (I assume due to size
>>> of 2 byte integer). This limitation was lifted (and the change of
>>> behavior documented), therefore I concluded that it was Microsoft's
>>> intention that more than 32768 items could now be added.
>>>
>>> I also believe, with nothing to support it!, that some aspect of
>>> ShowDialog() is the problem. I think this because once the list box is
>>> loaded, and the dialog is hidden and then reopened, the problem
>>> manifests itself again. The constructor is not executed on subsequent
>>> calls to ShowDialog() (I have verified that in the debugger), therefore
>>> the listbox is already loaded.
>>>
>>> I was wondering if there is some callback that gets executed once per
>>> item on each call to ShowDialog(). Item drawing only occurs for each
>>> item that is in view, so that probably rules out any problems with GDI.
>>>
>>> I have redesigned the dialog to narrow the data down to manageable
>>> proportions, but the original design is the superior UI (a user using
>>> only the keyboard can select any of the 50000 records in a very short
>>> time). The bottom line is that if you have to select records in three
>>> list boxes (the minimum possible given the nature of the data), this is
>>> bound to be slower than selecting a record in one list box.
>>>
>>> I still would like to find out what is causing the unwanted behavior,
>>> and would appreciate any help. I have MSDN Universal - is there a source
>>> code performance analyzer that I could understand how to use in a short
>>> time (< 1/2 a day) that will track execution within Windows modules?
>>>
>>> I appreciate any help.
>>>
>>> "Shaftoe" <Shaftoe@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>> news:61488D2E-4097-4784-A785-F5C520FC5E96@xxxxxxxxxxxxxxxx
>>>> The fact that you are loading a list with 50K items is what is causing
>>>> the
>>>> slowdown. either load with a more reasonable amount of data or if that
>>>> is
>>>> impossible, spin the load process off into another thread.
>>>> You can also load your values if fairly static, as an array list of
>>>> classes
>>>> and then bind the list box to the array list. But the bottom line
>>>> here is
>>>> that 50k of any data is too much and will cause performance issues.
>>>>
>>>> "Valerie Hough" wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Development is done under XP SP2, C# .NET, Visual Studio .NET 2003,
>>>>> .NET
>>>>> v1.1
>>>>>
>>>>> I have a System.Windows.Form that displays a dialog when a button is
>>>>> pressed.
>>>>>
>>>>> The dialog has a list box, a text box used as a typing helper, and two
>>>>> buttons in it.
>>>>>
>>>>> The list box has approximately 50,000 items in it.
>>>>>
>>>>> The first time the dialog is displayed it takes over 20 seconds, and
>>>>> even
>>>>> subsequent calls to show it take almost as long (a mere 18-19
>>>>> seconds), even
>>>>> though the documentation says that any calls to ShowDialog() after the
>>>>> first
>>>>> one are really only changing the visibility of the dialog.
>>>>>
>>>>> In the Visual Studio debugger, it is the actual call to ShowDialog()
>>>>> that is
>>>>> taking so long.
>>>>>
>>>>> Task manager shows intense CPU activity during the 20 seconds, but
>>>>> little
>>>>> memory activity.
>>>>>
>>>>> With only a few thousand items there is no problem.
>>>>>
>>>>> Once the dialog is displayed, I use a typing helper to scroll the list
>>>>> box
>>>>> to different places; this all happens very quickly - no performance
>>>>> issues
>>>>> at all once it is displayed.
>>>>>
>>>>> Are there any callbacks that could be being invoked during
>>>>> ShowDialog() ?
>>>>>
>>>>> Can anyone help?
>>>>>
>>>>> Thanks in advance,
>>>>> Chris Hough
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>>
>
>


.


Quantcast