Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If there way to break out of a construct like this?

Array.ForEach(
              properties,
              p =>
                {
                  ListViewItem LVI = DisplayPropertyValue(p);
                  if (LVI.Text != "")
                    aReturn.Add(LVI);
                });


I'd like to be able to set a "Cancel" bool to abandon it and go on to something more interesting. I can't find anyplace to put the conditional that doesn't give me syntax errors.

Another way to do it?
Posted

1 solution

The ForEach isn' t meant for that. It looks like you could use the Find or Exists to do what you want although they aren't actually meant for that as well. In these situations it is better to simply do it the "old fashion way" instead of shoehorning it in.

Another option is to create your own iterator:
http://msdn.microsoft.com/en-us/magazine/cc163682.aspx[^]

Good luck!
 
Share this answer
 
v3
Comments
GenJerDan 16-Dec-10 23:08pm    
Thanks. Unraveled it and put a break in...but it seems canceling a backgroundworker doesn't actually cancel much of anything until it feels like it, so it didn't make a difference. Sigh. Guess the app is as tweaked as it gets. On to writing the help file. Yecch.
E.F. Nijboer 17-Dec-10 4:29am    
About this you wrote: "but it seems canceling a backgroundworker doesn't actually cancel much of anything"
You have to check the CancellationPending to determine within the worker thread if CancelAsync is called and if accordingly should abort. Maybe this info can help you with that.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.cancellationpending.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900