Are there any know bugs with the ListView in .NET 2? I'm having
problems with an application that takes 15 seconds in 1.1, and now
takes over a minute. The code in question uses:
listViewItem = this.listView1. Items.Add(...)
followed by 7 calls to
listViewItem.Su bItems.Add(...)
When I comment out this code, the application runs in the same time as
the 1.1 version.
Any suggestions? I can provide the source code if required.
May 31 '06
18 1966
Chris Dunaway wrote: Just a thought:
Do you have any try catches that might be swallowing an exception? Perhaps an exception is being generated and swallowed.
Spot on! For some reason the following code:
private int ConvertToInt(st ring input)
{
if ( input != null && input != "" )
{
try
{
int retvalue = Convert.ToInt32 (input);
return retvalue;
}
catch
{
return 0;
}
}
else
{
return 0;
}
}
was slowing down the application hugely ("A first chance exception of
System.FormatEx ception was caught") in .NET 2.0 but not 1.1. This might
be the debugger, I didn't check. Anyway as I'm using 2.0 I just changed
the above method to:
private int ConvertToInt(st ring input)
{
if ( input != null && input != "" )
{
int result = 0;
int.TryParse(in put, out result);
return result;
}
else
{
return 0;
}
}
Just a quick note - for performance and also readability reasons, you should
use string.IsNullOr Empty() instead of checking for null and string.Empty
equality.
<mr*********@go oglemail.com> wrote in message
news:11******** **************@ c74g2000cwc.goo glegroups.com.. . Chris Dunaway wrote: Just a thought:
Do you have any try catches that might be swallowing an exception? Perhaps an exception is being generated and swallowed.
Spot on! For some reason the following code:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { try { int retvalue = Convert.ToInt32 (input); return retvalue; } catch { return 0; } } else { return 0; } }
was slowing down the application hugely ("A first chance exception of System.FormatEx ception was caught") in .NET 2.0 but not 1.1. This might be the debugger, I didn't check. Anyway as I'm using 2.0 I just changed the above method to:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { int result = 0; int.TryParse(in put, out result); return result; } else { return 0; } }
Most likely this was the debugger, then; exceptions are actually damned
fast - but the IDE makes 'em look slow.
You may also be able to simplify this to:
private int ConvertToInt32( string input) {
int result;
int.TryParse(in put, out result); // discard returned bool
return result;
}
(I also hacked the name just to be pedantic with the CLR guidelines - but
since this method is private it is purely academic)
Marc
Lebesgue,
While I agree that IsNullOrEmpty does improve readability, I fail to see
how it is an improvement to performance. The code is pretty much the same
in the IsNullOrEmpty method and what is being done here.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Lebesgue" <le******@gmail .com> wrote in message
news:eB******** ******@TK2MSFTN GP02.phx.gbl... Just a quick note - for performance and also readability reasons, you should use string.IsNullOr Empty() instead of checking for null and string.Empty equality.
<mr*********@go oglemail.com> wrote in message news:11******** **************@ c74g2000cwc.goo glegroups.com.. . Chris Dunaway wrote: Just a thought:
Do you have any try catches that might be swallowing an exception? Perhaps an exception is being generated and swallowed.
Spot on! For some reason the following code:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { try { int retvalue = Convert.ToInt32 (input); return retvalue; } catch { return 0; } } else { return 0; } }
was slowing down the application hugely ("A first chance exception of System.FormatEx ception was caught") in .NET 2.0 but not 1.1. This might be the debugger, I didn't check. Anyway as I'm using 2.0 I just changed the above method to:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { int result = 0; int.TryParse(in put, out result); return result; } else { return 0; } }
Nicholas,
While I understand that == call is delegated to Equals, which checks for
string length equality in the first place, which has basically the same
effect as IsNullOrEmpty call, according to FxCop rules, it yields execution
of significantly more MSIL instructions, thus should be avoided to achieve
the best peformance [1].
I believe the difference would be very subtle - but there certainly is some,
when it's listed as FxCop rule.
[1] FxCop Documentation 1.312.0: http://www.gotdotnet.com/team/fxcop/...ingLength.html
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:O2******** ******@TK2MSFTN GP04.phx.gbl... Lebesgue,
While I agree that IsNullOrEmpty does improve readability, I fail to see how it is an improvement to performance. The code is pretty much the same in the IsNullOrEmpty method and what is being done here.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Lebesgue" <le******@gmail .com> wrote in message news:eB******** ******@TK2MSFTN GP02.phx.gbl... Just a quick note - for performance and also readability reasons, you should use string.IsNullOr Empty() instead of checking for null and string.Empty equality.
<mr*********@go oglemail.com> wrote in message news:11******** **************@ c74g2000cwc.goo glegroups.com.. . Chris Dunaway wrote: Just a thought:
Do you have any try catches that might be swallowing an exception? Perhaps an exception is being generated and swallowed.
Spot on! For some reason the following code:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { try { int retvalue = Convert.ToInt32 (input); return retvalue; } catch { return 0; } } else { return 0; } }
was slowing down the application hugely ("A first chance exception of System.FormatEx ception was caught") in .NET 2.0 but not 1.1. This might be the debugger, I didn't check. Anyway as I'm using 2.0 I just changed the above method to:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { int result = 0; int.TryParse(in put, out result); return result; } else { return 0; } }
Ok, I see what you are saying, yes, it will delegate to Equals, but
ultimately, the first check in the Equals overload is against the length.
It might be a few more IL statements, but I don't know how much exactly.
In the end, it's a moot point, since the readability aspect definitely
makes it more attractive.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Lebesgue" <le******@gmail .com> wrote in message
news:en******** ******@TK2MSFTN GP03.phx.gbl... Nicholas,
While I understand that == call is delegated to Equals, which checks for string length equality in the first place, which has basically the same effect as IsNullOrEmpty call, according to FxCop rules, it yields execution of significantly more MSIL instructions, thus should be avoided to achieve the best peformance [1].
I believe the difference would be very subtle - but there certainly is some, when it's listed as FxCop rule.
[1] FxCop Documentation 1.312.0: http://www.gotdotnet.com/team/fxcop/...ingLength.html
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:O2******** ******@TK2MSFTN GP04.phx.gbl... Lebesgue,
While I agree that IsNullOrEmpty does improve readability, I fail to see how it is an improvement to performance. The code is pretty much the same in the IsNullOrEmpty method and what is being done here.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Lebesgue" <le******@gmail .com> wrote in message news:eB******** ******@TK2MSFTN GP02.phx.gbl... Just a quick note - for performance and also readability reasons, you should use string.IsNullOr Empty() instead of checking for null and string.Empty equality.
<mr*********@go oglemail.com> wrote in message news:11******** **************@ c74g2000cwc.goo glegroups.com.. . Chris Dunaway wrote: > Just a thought: > > Do you have any try catches that might be swallowing an exception? > Perhaps an exception is being generated and swallowed.
Spot on! For some reason the following code:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { try { int retvalue = Convert.ToInt32 (input); return retvalue; } catch { return 0; } } else { return 0; } }
was slowing down the application hugely ("A first chance exception of System.FormatEx ception was caught") in .NET 2.0 but not 1.1. This might be the debugger, I didn't check. Anyway as I'm using 2.0 I just changed the above method to:
private int ConvertToInt(st ring input) { if ( input != null && input != "" ) { int result = 0; int.TryParse(in put, out result); return result; } else { return 0; } }
So can anyone shed light here on why the ConvertToInt was taking .NET
2.0 so much longer to run than 1.1? Is it the changes to the VS.NET
debugger? Or something in the framework?
Well, the saga continues. The problem was being veiled by the
ConvertToInt inside the business logic part of the code. I have now
added:
Application.Ena bleVisualStyles ();
inside Main. This is actually the source of my problem. Remove it and
the application runs the same speed as the .NET 1.1. Include it and it
runs 4x as slow.
Source code is at: http://www.google.com/url?sa=D&q=htt...1-dbe878a161b7
If anyone can spare 5 mins to try running it on .NET 1.1 and .NET 2.0,
and add Application.Ena bleVisualStyles (); to Main() and see if they get
the same speed difference. Use testlog.log as the example log.
On 31 May 2006 05:59:54 -0700, "mr*********@go oglemail.com"
<mr*********@go oglemail.com> wrote: It's over 6000 items I'm adding, here's a snippet:
If you are adding 6000 items I really recommend that you use AddRange.
It is significantly (several times) faster than Add when dealing with
large numbers of items. I don't usually use SubItems.Add, but instead
use the constructor that takes a string array.
Here is a some code (slightly modified for simplicity) from one of my
applications that has a ListView with about 10000 items. It takes
about a second to fill it.
private void FillListView()
{
listView.BeginU pdate();
listView.Items. Clear();
//We add to a List(Array) first because AddRange is a lot faster
//than Add when dealing with lots of elements in ListView
//Also, we don't seem to have to turn off the sorter when adding
//all the elements at once
List<ListViewIt em> items = new List<ListViewIt em>();
foreach (Episode episode in episodes)
items.Add(Creat eEpisodeListVie wItem(episode)) ;
listView.Items. AddRange(items. ToArray());
listView.EndUpd ate();
}
private static ListViewItem CreateEpisodeLi stViewItem(Epis ode
episode)
{
ListViewItem item = new ListViewItem(
new string[]
{
episode.Origina lAirdate.HasVal ue?
episode.Origina lAirdate.Value. ToShortDateStri ng():"",
episode.Show.Na me,
episode.Season. ToString(),
episode.Episode Number.ToString (),
episode.Title
});
item.Tag = episode;
return item;
}
--
Marcus Andrén This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Mateer |
last post by:
Hi,
I have been running some queries against a table in a my database and
have noted an odd (at least it seems odd to me) performance issue.
The table has approximately 5 million rows and includes the following
columns:
DocID (INTEGER, PRIMARY KEY, CLUSTERED)
IsRecord (INTEGER, NONCLUSTERED)
|
by: Mortisus |
last post by:
Hi, I'm running a fulltext query on a ~50000 record mysql database and
while performance is usually satisfying - about 0.02 secs per query, i
get a critical performance deterioration when looking for popular
keywords (words that appear in more than 50% of the data) - about 0.25
secs/query. I know that the standard fulltext engine does not return
any results on such words, and this is good, but this does not explain
the performance issue....
|
by: bob |
last post by:
Currently i'm writing some low level communication modules in C++ and
is thinking of putting it into a library so that it can be used in C#.
My concern is the performance issue when putting C++ codes into C#.
Does anyone has any idea(s) on this issue????
|
by: 57R4N63R |
last post by:
I'm currently building a website for one of the client. There has been
few errors here and there, but just recently the problem is getting worse.
Basically the symptoms is that when the user try to access the page, it
takes really long time to load. However, after up to 1 hour, the website
will run fine again as normal.
This issue has been there with the site. I usually just ask the system
admin to restart the IIS Service. However, the...
|
by: Ira Siyal |
last post by:
Hi
I had a project in VB6 which I upgraded to VB.NET recently.
In the app, I am facing some issue with listview control. In the earlier
app, I have set the Icons in listview through an imagelist.
but i notice that while i execute the project in .net, the step that sets
the icon prop. throws an exception.
| |
by: Varangian |
last post by:
Hi,
I have a performance issue question?
which is best (in terms of efficiency and performance, I don't care
neatness in code)... building an ArrayList of Object Instances using
SqlDataReader OR using SqlDataAdapter to Fill a DataSet or DataTable ?
Thanks!
|
by: Shades799 |
last post by:
Hi All,
I was wondering if any of you could help me with a very difficult problem that I am having.
I have an ASP site that works with an Oracle database using an ADODB connection. This connection is stored in a .dll file. This site had been working fine.
However recently we upgraded our Oracle database from 9i to 10g and ever since then we have been having serious performance problems with this site only.
The website works fine...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |