(I searched for similar topics and could not find anything that related to this particular problem, although there were several similar ones, such as here and.)
I evaluate the performance of our application, and I notice that we get some IOExceptions "Unable to find resource." I don’t know exactly how many times this happens (it depends a lot on how the user uses the application), but this is not less than a dozen or so.
I assume that exceptions in general are costly in performance, as are file I / O calls, for example File.Exists(). I know that it is always useful to check if a file exists before trying to download it. My question is: how much can I increase performance if I check if this particular file exists? (Again, ignore "you should do this anyway", I'm just trying to understand the idea of performance).
Option 1:
try
{
return (ResourceDictionary) Application.LoadComponent(uri);
}
catch (Exception)
{
}
This does not make an additional I / O call, but sometimes throws an exception that is swallowed.
Option 2 :
if(File.Exists(uri))
{
return (ResourceDictionary) Application.LoadComponent(uri);
}
Devin source
share