Discussion:
Funny Comparison with Float
Brady Kelly
2008-03-06 13:57:44 UTC
Permalink
Barry Kelly
2008-03-06 14:13:37 UTC
Permalink
Brady Kelly
2008-03-06 14:22:14 UTC
Permalink
Ryan Heath
2008-03-06 14:15:44 UTC
Permalink
Not to say that I am an floating expert :)

The literal 1.1 is a double.

You are comparing an float 1.1 with an double 1.1

Due to rounding errors, the double will contain a better approx. value
of 1.1 than the float does.

BTW, you never should check floats or doubles with an equal sign.
Always use a greater or less sign.

// Ryan

On Thu, Mar 6, 2008 at 2:57 PM, Brady Kelly <***@chasesoftware.co.za> wrote:
> My colleague has just noticed a funny in comparing a float to a literal
> value. Where 'version' is a 'float', the expression "version == 1.1"
> evaluates to false, where the comparison "version == 1.1F" does. Last
> week's thread on floating point maths prompted me to raise the issue here to
> find out from the experts just what happens here.
>
>
> ===================================
> This list is hosted by DevelopMentor(R) http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Brady Kelly
2008-03-06 14:19:52 UTC
Permalink
Jon Skeet
2008-03-06 14:29:50 UTC
Permalink
Brady Kelly wrote:
> My colleague has just noticed a funny in comparing a float to a literal
> value. Where 'version' is a 'float', the expression "version == 1.1"
> evaluates to false, where the comparison "version == 1.1F" does. Last
> week's thread on floating point maths prompted me to raise the issue here to
> find out from the experts just what happens here.

One point that no-one else has picked up on yet (as far as I've seen) -
what is "version" doing as a binary floating point number anyway?
Assuming it's a version number in a normal kind of way, it should really
be a decimal (or a string).

Binary floating point (float/double) is best used for values which a
measurements of real-world values which have infinite variation -
length, mass etc.

Decimal floating point (the decimal type) is good for values which are
inherently decimal to start with, money being the obvious example.

You may or may not find my short articles about floating point useful:
http://pobox.com/~skeet/csharp/floatingpoint.html
http://pobox.com/~skeet/csharp/decimal.html


Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Rich Armstrong
2008-03-06 15:16:23 UTC
Permalink
Jon Skeet
2008-03-06 15:22:18 UTC
Permalink
Rich Armstrong wrote:
> Jon Skeet wrote:
>>> Assuming it's a version number in a normal kind of way, it should really
>>> be a decimal (or a string).
>
> ... or even a System.Version.

Well, that depends on what it's versioning. If you're versioning
something which has nothing to do with .NET, and only needs a major and
minor number, I'm not sure I'd use a version number with 4 parts where
the class describes itself in terms of versioning a CLR assembly.

I'm sure it would work, but it also has disadvantages such as ToString()
including the two unnecessary parts.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Rich Armstrong
2008-03-06 15:38:53 UTC
Permalink
Of course it may or may not be appropriate for the original poster's purpose,
but if someone were looking for a better way to represent a version than a float
or double, it's worth considering.

If you do need versions with more than two parts ("in a normal kind of way"),
System.Version provides some nice features, like comparison semantics and the
various ToString() overloads. We've used it to version all sorts of non-CLR
things; my only complaint has been that the class is sealed, forcing us to write
a wrapper class for one of our applications.

Just my 2¢.

-----Original Message-----
From: Discussion of development on the .NET platform using any managed language
[mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
Sent: Thursday, March 6, 2008 9:22 AM
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Funny Comparison with Float

Rich Armstrong wrote:
> Jon Skeet wrote:
>>> Assuming it's a version number in a normal kind of way, it should really
>>> be a decimal (or a string).
>
> ... or even a System.Version.

Well, that depends on what it's versioning. If you're versioning
something which has nothing to do with .NET, and only needs a major and
minor number, I'm not sure I'd use a version number with 4 parts where
the class describes itself in terms of versioning a CLR assembly.

I'm sure it would work, but it also has disadvantages such as ToString()
including the two unnecessary parts.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
silky
2008-03-06 22:56:19 UTC
Permalink
On Fri, Mar 7, 2008 at 2:38 AM, Rich Armstrong <***@msn.com> wrote:
> Of course it may or may not be appropriate for the original poster's purpose,
> but if someone were looking for a better way to represent a version than a float
> or double, it's worth considering.

I personally use a string which I then convert to a long for
comparisions. It does mean that I make my version numbers a fixed
maximum length (6 chars per segment) but then I can just extend out
each segment and whack it into one long which I then compare
trivially.


> If you do need versions with more than two parts ("in a normal kind of way"),
> System.Version provides some nice features, like comparison semantics and the
> various ToString() overloads. We've used it to version all sorts of non-CLR
> things; my only complaint has been that the class is sealed, forcing us to write
> a wrapper class for one of our applications.
>
> Just my 2¢.

--
http://lets.coozi.com.au/

There's not a problem I can't fix, because I can do it in the mix.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
David Nicholson
2008-03-07 16:13:01 UTC
Permalink
On Thu, 6 Mar 2008 15:22:18 +0000, Jon Skeet <***@POBOX.COM> wrote:

>Rich Armstrong wrote:
>> Jon Skeet wrote:
>>>> Assuming it's a version number in a normal kind of way, it should
really
>>>> be a decimal (or a string).
>>
>> ... or even a System.Version.
>
>Well, that depends on what it's versioning. If you're versioning
>something which has nothing to do with .NET, and only needs a major and
>minor number, I'm not sure I'd use a version number with 4 parts where
>the class describes itself in terms of versioning a CLR assembly.
>
>I'm sure it would work, but it also has disadvantages such as ToString()
>including the two unnecessary parts.
>
>Jon

I didn't even know there was such a class, but looking at the docs you can
keep it to two parts if you want (including ToString()).

David.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Rich Armstrong
2008-03-07 20:28:56 UTC
Permalink
Keith Hill
2008-03-07 16:55:12 UTC
Permalink
Marc Brooks
2008-03-07 17:59:30 UTC
Permalink
> It is a bit more complicated than that. A robust "AlmostEquals" routine
> would handle not only epsilon (I'd use something like 1E-5) but also Inf,
> NaN and overflow when adding and/or subtracting the two values to
> compare to epsilon). You might check around for a math library that does
> this.

My Utilities class library has an almost-equal for doubles that lets
you indicate how many "last digits" can differ, and thus is correct
when the magnitude of the values is not near-zero (which is the only
place Double.Epsilon is useful).

http://idisposable.googlepages.com/

--
"He uses statistics as a drunken man uses lamp-posts… for support
rather than illumination." Andr
Peter Ritchie
2008-03-07 16:55:34 UTC
Permalink
If only the framework contained useful[1] values for Epsilon.

[1] https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?
FeedbackID=93726&wa=wsignin1.0

On Fri, 7 Mar 2008 09:55:12 -0700, Keith Hill <***@AGILENT.COM>
wrote:

>> -----Original Message-----
>> From: Brady Kelly [mailto:***@CHASESOFTWARE.CO.ZA]
>> Sent: Thursday, March 06, 2008 7:20 AM
>> Subject: Re: Funny Comparison with Float
>>
>> > BTW, you never should check floats or doubles with an equal sign.
>> > Always use a greater or less sign.
>> >
>> > // Ryan
>>
>> Like 'version > 1 && version < 1.11' ?
>>
>
>It is a bit more complicated than that. A robust "AlmostEquals" routine
would handle not only epsilon (I'd use something like 1E-5) but also Inf,
NaN and overflow when adding and/or subtracting the two values to compare
to epsilon). You might check around for a math library that does this.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Barry Kelly
2008-03-08 03:56:09 UTC
Permalink
Dean Cleaver
2008-03-10 09:20:07 UTC
Permalink
Ryan Heath
2008-03-10 09:28:04 UTC
Permalink
Because properties are implemented underneath as functions.
get_PropName
set_PropName

A ref argument cannot point to a func, and if it did, it would point
to the wrong function in any case.

ref arg needs the passing value; it would need the get_PropName function for it.
but ref arg needs to set the value as well; it would need the
set_PropName function for it.

HTH
// Ryan

On Mon, Mar 10, 2008 at 10:20 AM, Dean Cleaver
<***@xceptionsoftware.com> wrote:
> I can understand ref arguments, because they might not be set on
> passing, but I can't figure out why they can't be used as out arguments?
>
> Any thoughts?
>
> Dino
>
> ===================================
> This list is hosted by DevelopMentor(R) http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 09:33:48 UTC
Permalink
Jon Skeet
2008-03-10 09:45:36 UTC
Permalink
Dean Cleaver wrote:
> Ah. Yes. Didn't think of the actual mechanics of how it presented the
> properties behind it all. Thank you.
>
> Is a shame though - or is there any way I can get around it using
> delegates? I have a function that I require to set one of two
> properties, and return a 3rd?

Is it sufficiently general that you could create an interface with the
properties in, and then pass an implementation of that interface into
the method?

You certainly *could* do it with delegates, but it would feel a little ugly.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 10:52:45 UTC
Permalink
Jon Skeet
2008-03-10 09:32:08 UTC
Permalink
Dean Cleaver wrote:
> I can understand ref arguments, because they might not be set on
> passing, but I can't figure out why they can't be used as out arguments?
>
> Any thoughts?

That's not the reason for not being able to use them as ref.

When you pass a parameter by out/ref, you're effectively passing an
address that the called method can use as the variable address. It can
treat it like any other variable in terms of storing and fetching values
directly (subject to definite assignment rules for out, of course).

Properties don't work like this - they're not slots in memory, to be
arbitrarily accessed.


Note that if you use properties for out/ref parameters in VB, basically
a temporary variable is created, *that* is passed by out/ref, and the
property is set appropriately after method has completed.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 09:44:10 UTC
Permalink
Jon Skeet
2008-03-10 09:55:39 UTC
Permalink
Dean Cleaver wrote:
> Yeah - getting my head around it now. Sadly, it's not VB I wanted it
> for.
>
> Is a shame- looks like I will have to declare 2 variables, pass them in,
> and then analyse the returned responses to achieve what I want - takes
> the "ideal" 1 line call to about 7 or 8 at least - was trying to
> encapsulate a call, but it might not be feasible.

Sounds like an argument for tuple return types:

(FirstNameProperty, LastNameProperty) = SplitName(FullName);

:)

(Can you tell I've been learning Erlang? ;)

I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
silky
2008-03-10 10:33:51 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Mar 10, 2008 at 8:55 PM, Jon Skeet wrote:
> Dean Cleaver wrote:
> > Yeah - getting my head around it now. Sadly, it's not VB I wanted it
> > for.
> >
> > Is a shame- looks like I will have to declare 2 variables, pass them in,
> > and then analyse the returned responses to achieve what I want - takes
> > the "ideal" 1 line call to about 7 or 8 at least - was trying to
> > encapsulate a call, but it might not be feasible.
>
> Sounds like an argument for tuple return types:
>
> (FirstNameProperty, LastNameProperty) = SplitName(FullName);
>
> :)
>
> (Can you tell I've been learning Erlang? ;)
>
> I've no idea how much work is required either in terms of language
> design or CLR modifications to support this - I suspect it would be
> feasible in "language only" but a lot more elegant with CLR integration.

Yeah I'd like this too, but I have vague feelings that it can be done
with an anonymous class. Is there such a thing? probably not. But I do
note that creating 'quick' classes is a bit easier in 3.0 ... multiple
assignments from functions would be useful though.

(a, b, c) = foo(m);

public (string, int, double) foo (int m) { }

- --
http://lets.coozi.com.au/

There's not a problem I can't fix, because I can do it in the mix.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: http://firegpg.tuxfamily.org

iQEVAwUBR9UOgE4i+6wd5ptaAQIgDwf8CWLmxkFowVzVq5Qm96Zyx1JHH+bXfyjr
pus/FVvJpoPPRKjZfj8gk/fDJUeIhN4YcAJ3uoPCo1yQfl2qZV1Tefz0JYcmfzOo
k+v4m4CYnKL1QjYqM3vfHd9J95lx2FCNUmjqmV4qJxyAn/xvqA54PmrqBF/LImFs
92HBOPInWTJ/4e8ME9wknkc9enHtduNqLk9wOO83trulFRzpfBmPS26R9xlqrBx3
sK1TCREXyUFvRAgsE+l2QjRnFoIL46iBbu/uzIdV6eUChfYKa7K8I3G3Cpn8oYCk
lU8bBn0c5MvXmPEotT4SIJxX0SWbwfQCXFPqOCvMBclRgqinUk1vOw==
=J28+
-----END PGP SIGNATURE-----

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Jon Skeet
2008-03-10 10:37:17 UTC
Permalink
silky wrote:
>> I've no idea how much work is required either in terms of language
>> design or CLR modifications to support this - I suspect it would be
>> feasible in "language only" but a lot more elegant with CLR integration.
>
> Yeah I'd like this too, but I have vague feelings that it can be done
> with an anonymous class. Is there such a thing?

There are indeed anonymous types in C# 3, but they aren't easily
returned from a method in a strongly typed way.

Jon

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 10:45:31 UTC
Permalink
Barry Kelly
2008-03-10 10:57:42 UTC
Permalink
Dean Cleaver <***@XCEPTIONSOFTWARE.COM> wrote:

> Problem is my variables are of differing types... not that I can tell
> from your code snippet, but It seems they are expected to be the same
> type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

> -----Original Message-----
> From: Discussion of development on the .NET platform using any managed
> language [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
> Sent: Monday, 10 March 2008 22:56
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
> arguments
>
> Dean Cleaver wrote:
> > Yeah - getting my head around it now. Sadly, it's not VB I wanted it
> > for.
> >
> > Is a shame- looks like I will have to declare 2 variables, pass them
> in,
> > and then analyse the returned responses to achieve what I want - takes
> > the "ideal" 1 line call to about 7 or 8 at least - was trying to
> > encapsulate a call, but it might not be feasible.
>
> Sounds like an argument for tuple return types:
>
> (FirstNameProperty, LastNameProperty) = SplitName(FullName);
>
> :)
>
> (Can you tell I've been learning Erlang? ;)
>
> I've no idea how much work is required either in terms of language
> design or CLR modifications to support this - I suspect it would be
> feasible in "language only" but a lot more elegant with CLR integration.
>
> Jon
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com

-- Barry

--
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 11:00:11 UTC
Permalink
Shawn Wildermuth
2008-03-10 11:06:24 UTC
Permalink
Dean Cleaver
2008-03-10 11:12:33 UTC
Permalink
Richard Howells
2008-03-10 11:14:11 UTC
Permalink
Can you use a generic interface?

interface IWhatever<T, U, V>
{
T MyProp1 { get; set; }
U MyProp2 { get; set; }
V MyProp3 { get; set; }
}

class Blah<T, U, V> : IWhatever<T, U, V>
{
#region IWhatever<T,U,V> Members

public T MyProp1
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public U MyProp2
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public V MyProp3
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

#endregion
}

class Program
{
static void Main(string[] args)
{
Blah<string, int, bool> SpecialBlahForStringIntBool = new
Blah<string, int, bool>();

}
}
Cheers,

- Richard
***@dynamisys.co.uk
www.dynamisys.co.uk
(T) +44 (0) 1793 731225
(M) +44 (0) 773 297 1786

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Shawn
Wildermuth
Sent: 10 March 2008 11:06
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

I know its not terribly efficient, but couldn't you return a simple struct
or anonymous type with the multiple pieces of information?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthconsulting.com
http://geekdinners.com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

The Silverlight Tour is coming to a city near you!

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Dean Cleaver
Sent: Monday, March 10, 2008 7:00 AM
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <***@XCEPTIONSOFTWARE.COM> wrote:

> Problem is my variables are of differing types... not that I can tell
> from your code snippet, but It seems they are expected to be the same
> type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

> -----Original Message-----
> From: Discussion of development on the .NET platform using any managed
> language [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
> Sent: Monday, 10 March 2008 22:56
> To: DOTNET-***@DISCUSS.DEVELOP.COM
> Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
> arguments
>
> Dean Cleaver wrote:
> > Yeah - getting my head around it now. Sadly, it's not VB I wanted it
> > for.
> >
> > Is a shame- looks like I will have to declare 2 variables, pass them
> in,
> > and then analyse the returned responses to achieve what I want -
takes
> > the "ideal" 1 line call to about 7 or 8 at least - was trying to
> > encapsulate a call, but it might not be feasible.
>
> Sounds like an argument for tuple return types:
>
> (FirstNameProperty, LastNameProperty) = SplitName(FullName);
>
> :)
>
> (Can you tell I've been learning Erlang? ;)
>
> I've no idea how much work is required either in terms of language
> design or CLR modifications to support this - I suspect it would be
> feasible in "language only" but a lot more elegant with CLR
integration.
>
> Jon
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor(r) http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com

-- Barry

--
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentor(r) http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor. http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor. http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date: 09/03/2008
12:17


No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date: 09/03/2008
12:17

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-10 11:59:52 UTC
Permalink
Davy J
2008-03-10 15:20:37 UTC
Permalink
All our user controls are based off of one base control, that has a abstract
validate method and a readonly parameter.

/// <summary>
/// Sets the controls passed to readonly
/// </summary>
/// <param name="controls"> an array of controls or variable lenght params
, SetReadOnly(ucSearch,ucResults,ucActions) </param>
public void SetReadOnly(params BaseUserControl[] controls)

{
foreach (BaseUserControl buc in controls)
{
buc.ReadOnly = true;
}
}
and for validating our controls.

/// <summary>
/// Validates the controls.
/// </summary>
/// <param name="controls">1 or more user controls to
validate.</param>
/// <returns>List of Control / Message items.</returns>
public List<KeyValuePair<BaseUserControl, string>>
ValidateControls(params BaseUserControl[] controls)
{
List<KeyValuePair<BaseUserControl, string>> errors = new
List<KeyValuePair<BaseUserControl, string>>();
foreach (BaseUserControl buc in controls)
{
IValidate validate = buc.Validate();
if (validate != null)
{
errors.Add(new KeyValuePair<BaseUserControl,
string>(buc, validate.ErrorMessage));
}
}
return errors;
}


Davy J



On 3/10/08, Dean Cleaver <***@xceptionsoftware.com> wrote:
>
> Can you apply a generic 10 times to the same class to apply to 10
> different property pairs?
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-13 20:23:54 UTC
Permalink
Barry Kelly
2008-03-10 11:04:41 UTC
Permalink
Peter Ritchie
2008-03-13 20:37:59 UTC
Permalink
Ahh, the nebulous Object is currently in use elsewhere error.

This occurs directly out of GDI+. It occurs because GDI+ thinks you've
asked it to do two things at once with a single GDI object. This mostly
occurs when you try and do something with a GDI object on a background
thread (i.e. getting the size of an image on the main thread and modifying
an image on another thread constitutes doing two things at the same time
with GDI+.

Getting much more detail out of the exception won't help you much until
you find where the "other use" is.

On Fri, 14 Mar 2008 09:23:54 +1300, Dean Cleaver
<***@XCEPTIONSOFTWARE.COM> wrote:

>I've had this exception logged in my system:
>
>System.InvalidOperationException: Object is currently in use elsewhere.
> at System.Drawing.Image.get_Width()
> at System.Drawing.Image.get_Size()
> at
>System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSiz
>eMode mode)
> at System.Windows.Forms.PictureBox.get_ImageRectangle()
> at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
> at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs
>e, Int16 layer, Boolean disposeEventArgs)
> at System.Windows.Forms.Control.WmPaint(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at
>System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
> at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
>m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
>IntPtr wparam, IntPtr lparam)
>
>As you can see, none of it is my code - so any ideas on how I go about
>tracing what's causing it?

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Dean Cleaver
2008-03-13 20:53:24 UTC
Permalink
Peter Ritchie
2008-03-14 14:11:39 UTC
Permalink
On Fri, 14 Mar 2008 09:53:24 +1300, Dean Cleaver
<***@XCEPTIONSOFTWARE.COM> wrote:

>But I figured if it was my code using it, my code would have been
>included in the stack trace?

It depends on what code used the GDI object first. If it's your code then
the exception will occur somewhere else (in this case "system" code).
It's like locking on "this", if you code and system code lock on the same
object and your code locks first, the system code hangs.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Continue reading on narkive:
Loading...