comparing a function execution in a loop and outside loop in C#.

Hi;

I have a rather complex function call in a loop and want to check the state of the state of the objects affected by those function, comparing it in and outside the loop.

Any feasible way to do to compare?

Regards.
LVL 12
jazzIIIloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
No problem.
Run one inside of a separate thread then use some locking technique in the object to prevent dual access.

ps.  Your question doesn't really make sense, I suspect what I suggest isn't really what you want to do even though it is what you ask for.
0
jazzIIIloveAuthor Commented:
Hi;

I want to find the changes of the objects that the function may cause a change inside and outside of the loop.

Regards.
0
AndyAinscowFreelance programmer / ConsultantCommented:
OK, my first comment still does what you want.

ps.
Say your object has a int value.  Setting it to 42 will result in the object containing 42, it doesn't matter if you set that inside or outside of a loop.
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

jazzIIIloveAuthor Commented:
My object has several objects in it which may get affected.

Can you provide a simple code for this locking inside and outside of the loop?
0
AndyAinscowFreelance programmer / ConsultantCommented:
There are various possibilities to prevent simultaneous access to an object.  This is one method:

lock Statement (C# Reference), msdn reference site,

http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx
0
jazzIIIloveAuthor Commented:
but actually this is a comparison case. I mean I just need to test the behaviour of the same function inside and outside of the loop..
0
AndyAinscowFreelance programmer / ConsultantCommented:
A function will execute a piece of code.  It makes absolutely no difference to the objects it modifies if it is performing this inside a loop or outside.
If there is a difference it is because other actions are being performed on the object in only one of the two cases.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.