0

In my ASP.Net MVC application, I have to call to one user defined function. Whenever the page is refreshed, this function is called. Now what is the problem, for the first time, it runs perfect. But when I refresh, as I have put the breakpoint, it goes up and down repeatedly.

That means, debugger goes to line1, will run more than one time, then goes to second line, goes to third line, goes to first line, and so on. I have attached photos below. I am developing applications in MVC4.

enter image description here

enter image description here

enter image description here

enter image description here

First image is first time run. In second image, the line connection.Open() runs three times. It happens for every line. Debugger goes up and down abruptly. I don't know what is wrong with this. Can anybody explain this? Thank you.

2 Answers 2

2

It's definitely because of multiple threads running simultaneously.

Use this VS extension to limit your debugger hit on only 1 of the threads : https://visualstudiogallery.msdn.microsoft.com/54ef0f07-ed1d-4b89-b4ae-6506b196f843

Sign up to request clarification or add additional context in comments.

4 Comments

Well it's not only debugger. When I run application without debugging, thus happens. So I think limit the debugger would only when running with debugging. What do you suggest when application is live. The above code actually gets the records multiple times.
Have you checked the call stack of the code while debugging?
I mean compare the call stacks and see if they are being called by different methods or they're all the same. If they're the same then I presume you're sending duplicate requests from your view.
@DhavaIR, you need write lock statements on the server side, or change the client side to ensure to call your method only single time.
2

Sounds like the sort of thing you see when there are multiple threads calling your code.

Is it possible the code is actually being called multiple times by different threads?

To determine which threads are running when, use the Threads window of the debugger. Go to DEBUG > WINDOWS > THREADS

Here is more information on debugging multi-threaded apps: https://msdn.microsoft.com/en-us/library/ms164746.aspx

This should give you insight into which threads are hitting the breakpoints when.

Then inspect the call stack and see where the calls are coming from.

I'd also consider opening up Fiddler or the Network tab of your browser debugging tools and seeing if there are multiple requests being fired off which is resulting in your code being called multiple times - and then tracing back from there what is initiating those web requests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.