c_xyTopa
Wed Jan 23 16:30:06 CST 2008
This is a multi-part message in MIME format.
------=_NextPart_000_0013_01C85E17.E341FAF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Sorry...
For example here. This is an event-handle of the ui-layer to delete =
customer.
The _customerManager deletes customer from the list in the data-layer.
The _currentList is the reference to the list of the data-layer.
That means that the _currentList has one element less after that and =
actualy there is no need for the loop to delete the element for the =
second time...
List<Customer> _currentList =3D _customerManager.GetAll();
void view_DeleteCustomer(object sender, CustomerEventArgs e)
{
if (e.Customer =3D=3D null)
return;
Customer deleted =3D e.Customer;
deleted.Status =3D CustomerStatus.Deleted;
_customerManager.Delete(deleted);
// remove from the current list
foreach (Customer c in _currentList)=20
{
if (c.Guid.CompareTo(deleted.Guid) =3D=3D 0)
_currentList.Remove(c);
}
view.UpdateCustomerList(_currentList);
}
and a stack... The VS also points on keyword "in" of the loop.
bei System.ThrowHelper.ThrowInvalidOperationException()
at Enumerator.MoveNext()
bei =
Runtime.HakaMobile.Modules.CustomerModule.CustomersList.CustomerListPrese=
nter.view_DeleteCustomer()
bei =
Runtime.HakaMobile.Modules.CustomerModule.CustomersList.CustomerListView.=
DeleteCustomerMenuItem_Click()
bei System.Windows.Forms.MenuItem.OnClick()
bei System.Windows.Forms.Menu.ProcessMnuProc()
bei System.Windows.Forms.Form.WnProc()
bei System.Windows.Forms.Control._InternalWnProc()
bei Microsoft.AGL.Forms.EVL.EnterMainLoop()
bei System.Windows.Forms.Application.Run()
bei =
Microsoft.Practices.Mobile.CompositeUI.WinForms.FormShellApplication`2.St=
art()
bei Microsoft.Practices.Mobile.CompositeUI.CabApplication`1.Run()
bei Runtime.HakaMobile.Shell.ShellApplication.Main()
"<ctacke/>" <ctacke[at]opennetcf[dot]com> schrieb im Newsbeitrag =
news:edvO7NfXIHA.2268@TK2MSFTNGP02.phx.gbl...
> Well you've given us pretty much no useful information to go on. My =
guess=20
> is it's a bug in *your* iterator, not the CF.
>=20
>=20
> --=20
>=20
> Chris Tacke, eMVP
> Join the Embedded Developer Community
>
http://community.opennetcf.com
>=20
>=20
> "c_xyTopa" <a.dratchnev@runtime.de> wrote in message=20
> news:enVDz7eXIHA.1184@TK2MSFTNGP04.phx.gbl...
>> Hi all,
>>
>> I get InvalidOperationException while using foreach-loop.
>> It is not a rule, it just happens in some parts of code, in some - =
not.
>> As soon as I replace the foreach-loop by for-loop no Exception is=20
>> thrown...
>>
>> What can it be I wonder?
>>
>> Thanks in advance
>>=20
>=20
>
------=_NextPart_000_0013_01C85E17.E341FAF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16587" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY><FONT color=3D#0000ff size=3D2>
<DIV align=3Djustify><FONT face=3DArial =
color=3D#000000>Sorry...</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial color=3D#000000>For example =
here. This is=20
an event-handle of the ui-layer to delete customer.</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial color=3D#000000>The <FONT=20
face=3D"Times New Roman">_</FONT><FONT face=3D"Courier =
New">customerManager=20
</FONT><FONT face=3DArial>deletes customer from the list in the=20
data-layer.</FONT></FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial color=3D#000000><FONT =
face=3DArial><FONT=20
face=3D"Courier New"><FONT face=3DArial>The</FONT>=20
_currentList</FONT> is the reference to the list of the=20
data-layer.</FONT></FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial color=3D#000000>That means that =
the <FONT=20
face=3D"Courier New">_currentList </FONT><FONT face=3DArial>has one =
element less=20
after that and actualy there is no need for the loop to delete the =
element for=20
the second time...</FONT></FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial =
color=3D#000000></FONT> </DIV><FONT=20
color=3D#0000ff size=3D2>
<P align=3Djustify></FONT><FONT face=3D"Courier New"><FONT =
color=3D#2b91af=20
size=3D2>List</FONT><FONT color=3D#000000 size=3D2><</FONT><FONT =
color=3D#2b91af=20
size=3D2>Customer</FONT><FONT size=3D2><FONT color=3D#000000>> =
_currentList =3D <FONT=20
size=3D2>_customerManager.GetAll();</FONT></FONT></FONT></FONT></P>
<DIV><FONT face=3D"Courier New">void</FONT></FONT><FONT face=3D"Courier =
New"><FONT=20
size=3D2> view_DeleteCustomer(</FONT><FONT color=3D#0000ff =
size=3D2>object</FONT><FONT=20
size=3D2> sender, </FONT><FONT color=3D#2b91af=20
size=3D2>CustomerEventArgs</FONT></FONT><FONT size=3D2><FONT =
face=3D"Courier New">=20
e)</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT face=3D"Courier New">{</FONT></DIV>
<DIV></FONT><FONT face=3D"Courier New"><FONT color=3D#0000ff=20
size=3D2> if</FONT><FONT size=3D2> (e.Customer =3D=3D =
</FONT><FONT=20
color=3D#0000ff size=3D2>null</FONT></FONT><FONT size=3D2><FONT=20
face=3D"Courier New">)</FONT></DIV>
<DIV align=3Djustify></FONT><FONT face=3D"Courier New" color=3D#0000ff=20
size=3D2> return</FONT><FONT =
size=3D2><FONT=20
face=3D"Courier New">;</FONT></DIV>
<DIV align=3Djustify></FONT><FONT face=3D"Courier New" color=3D#2b91af=20
size=3D2> Customer</FONT><FONT size=3D2><FONT =
face=3D"Courier New">=20
deleted =3D e.Customer;</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =
deleted.Status =3D=20
</FONT></FONT><FONT face=3D"Courier New" color=3D#2b91af=20
size=3D2>CustomerStatus</FONT><FONT size=3D2><FONT=20
face=3D"Courier New">.Deleted;</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =20
_customerManager.Delete(deleted);</FONT></DIV>
<DIV align=3Djustify></FONT><FONT color=3D#008000 size=3D2><FONT=20
face=3D"Courier New"> // remove from the current=20
list</FONT></DIV></FONT><FONT size=3D2>
<DIV align=3Djustify></FONT><FONT face=3D"Courier New"><FONT =
color=3D#0000ff=20
size=3D2> foreach</FONT><FONT size=3D2> (</FONT><FONT=20
color=3D#2b91af size=3D2>Customer</FONT><FONT size=3D2> c </FONT><FONT =
color=3D#0000ff=20
size=3D2>in</FONT></FONT><FONT size=3D2><FONT face=3D"Courier New"> =
_currentList)=20
</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =
{</FONT></DIV>
<DIV align=3Djustify></FONT><FONT face=3D"Courier New" color=3D#0000ff=20
size=3D2> if</FONT><FONT =
size=3D2><FONT=20
face=3D"Courier New"> (c.Guid.CompareTo(deleted.Guid) =3D=3D =
0)</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =20
=
_currentList.Remove(c);</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =
}</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New"> =20
view.UpdateCustomerList(_currentList);</FONT></DIV>
<DIV align=3Djustify><FONT face=3D"Courier New">}</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial>and a stack... The VS also =
points on keyword=20
"in" of the loop.</FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial>bei=20
System.ThrowHelper.ThrowInvalidOperationException()<BR>at=20
Enumerator.MoveNext()<BR>bei=20
Runtime.HakaMobile.Modules.CustomerModule.CustomersList.CustomerListPrese=
nter.view_DeleteCustomer()<BR>bei=20
Runtime.HakaMobile.Modules.CustomerModule.CustomersList.CustomerListView.=
DeleteCustomerMenuItem_Click()<BR>bei=20
System.Windows.Forms.MenuItem.OnClick()<BR>bei=20
System.Windows.Forms.Menu.ProcessMnuProc()<BR>bei=20
System.Windows.Forms.Form.WnProc()<BR>bei=20
System.Windows.Forms.Control._InternalWnProc()<BR>bei=20
Microsoft.AGL.Forms.EVL.EnterMainLoop()<BR>bei=20
System.Windows.Forms.Application.Run()<BR>bei=20
Microsoft.Practices.Mobile.CompositeUI.WinForms.FormShellApplication`2.St=
art()<BR>bei=20
Microsoft.Practices.Mobile.CompositeUI.CabApplication`1.Run()<BR>bei=20
Runtime.HakaMobile.Shell.ShellApplication.Main()<BR></FONT></DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial> </DIV></FONT>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV>
<DIV align=3Djustify><FONT face=3DArial></FONT> </DIV></FONT>
<DIV>"<ctacke/>" <ctacke[at]opennetcf[dot]com> schrieb im=20
Newsbeitrag <A=20
href=3D"news:edvO7NfXIHA.2268@TK2MSFTNGP02.phx.gbl">news:edvO7NfXIHA.2268=
@TK2MSFTNGP02.phx.gbl</A>...</DIV>>=20
Well you've given us pretty much no useful information to go on. =
My guess=20
<BR>> is it's a bug in *your* iterator, not the CF.<BR>> <BR>> =
<BR>>=20
-- <BR>> <BR>> Chris Tacke, eMVP<BR>> Join the Embedded =
Developer=20
Community<BR>> <A=20
href=3D"
http://community.opennetcf.com">http://community.opennetcf.com</A=
><BR>>=20
<BR>> <BR>> "c_xyTopa" <<A=20
href=3D"mailto:a.dratchnev@runtime.de">a.dratchnev@runtime.de</A>> =
wrote in=20
message <BR>> <A=20
href=3D"news:enVDz7eXIHA.1184@TK2MSFTNGP04.phx.gbl">news:enVDz7eXIHA.1184=
@TK2MSFTNGP04.phx.gbl</A>...<BR>>>=20
Hi all,<BR>>><BR>>> I get InvalidOperationException while =
using=20
foreach-loop.<BR>>> It is not a rule, it just happens in some =
parts of=20
code, in some - not.<BR>>> As soon as I replace the foreach-loop =
by=20
for-loop no Exception is <BR>>> thrown...<BR>>><BR>>> =
What can=20
it be I wonder?<BR>>><BR>>> Thanks in advance<BR>>> =
<BR>>=20
<BR>></BODY></HTML>
------=_NextPart_000_0013_01C85E17.E341FAF0--