|
Jörgen Andersson wrote: doubt that TryParse would have made a difference.
Fewer puppies would have been killed. Don't use Convert.
|
|
|
|
|
If I don't expect the conversion to fail I want an exception.
When failure is expected I use TryParse.
There is a reason both exists.
|
|
|
|
|
Yes, in this case Parse is more appropriate. (I just updated my earlier response with an example.)
|
|
|
|
|
Jörgen Andersson wrote: But since it didn't throw an exception but rather make a correct conversion
What version of .NET? I've just tried Convert.ToInt32("42.") in LINQPad for 3.5 and 4.5, and both versions throw a FormatException .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Weird. If I try Convert.ToInt32("42.") in .NET 4.5, I get:
FormatException: Input string was not in a correct format.
Are you sure you're not doing something else in your code that's hiding the error?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Odd, I'have to check on monday when I'm back at work.
|
|
|
|
|
Jörgen Andersson (is this you "Neo"?!?) sounds scandinavian and they probably have a different decimal separator...
Robert
|
|
|
|
|
Good point. However, Convert.ToInt32("42,") still produces a FormatException .
Trying "42." with the "sv-SE" culture, which uses "," as the decimal separator and "." as the group separator, also produces a FormatException .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
3000 times slower? I noticed the extra character about 15 mins after you started this thread, but didn't think it relevant.
I'll have to keep an eye out for that... Almost as bad as the exponent operator in VB.NET... (Try benchmarking 2^2 vs Math.Pow(2,2))
|
|
|
|
|
hmm FileName.IndexOf('_') is calculated twice too
|
|
|
|
|
Well, a little late to the party, but this is why I have a whole bunch of string extensions, like this "Between" and "ToInt32":
FileName.Between('_', '.').ToInt32()
And then you would never have included the '.' by accident.
Marc
|
|
|
|
|
Just put that on my todo list.
|
|
|
|
|
Send me a direct email and I'll send you the .cs file of my extensions.
There's this[^] too.
Marc
|
|
|
|
|
very cool (aka )
'g'
|
|
|
|
|
Whereas the number of threads should be known in advance, the architecture of this application is so bad, that this check has been added before launching new threads, to avoid the ThreadPool to explode :
var count = Process.GetCurrentProcess().Threads.Count;
if (count > maxApplicationThreadCount) return;
Cheers
|
|
|
|
|
Well, having a lot of threads isn't necessarily a bad thing. It depends on what they're doing. If they're sitting around waiting for some async process to complete, then should be OK. But if they're all competing for CPU time doing heavy processing, then yeah, that's not good.
Marc
|
|
|
|
|
Also nice to note that it prevents the creation of new threads only after the maximum number has been exceeded...
|
|
|
|
|
...which also implies that there is no feedback to the calling function whether the new thread has been started, or not. Interesting, at least.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
Well, it's a timer (that is never stopped) that creates a worker thread in its callback method, so if there is too much threads, then... no work will be started.
This check has been added because the duration of the worker thread was sometimes longer than the timer interval, so the number of threads was increasing indefinitely !
|
|
|
|
|
If anything, this is a very good description on how we work here.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
def widthOfLength(s: String) = s.length.toString.length
|
|
|
|
|
Do you think they [or you ] chose width, as lengthOfLength(s: String) = s.length.toString.length would cause a meltdown.
|
|
|
|
|
I have to admit that "widthOfLength" seems OK to me. Obviously it is used to calculate the format/layout of some table perhaps where all the lengths are scanned to find the longest/widest. It is just a matter of semantics.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
You're absolutely right about the code purpose.
|
|
|
|