Weird behavior of asp.net mvc application. - asp.net-mvc

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.
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.

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

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.

Related

how to know that where exactly app getting stuck in xcode?

My app gets stuck for a specific operation and that operation is too big having so many method calls and services requests, so i cannot put breakpoints on each method and debug, is there any other way i can get to know where exactly my app is stucked in xcode?
The operation wasn't too big to write the code, so it isn't too big to add breakpoints, logging statements, assertions and so on.
The only other way that works sometimes is taking a long shower in the morning, not thinking about work at all, and suddenly the realisation what you did wrong jumps to your mind. It has worked for me sometimes, but the first method is more reliable.
If you have reason to believe that the most time is spent in one operation, just let it run with the debugger attached and then press the pause button and see where you are...
A somewhat niftier approach would be to start with Instruments (i.e. the Time Profiler). It's easy to use and should be the first weapon of your choice for performance issues.
You can set a conditional break point in Xcode to debug a specific condition, for more detail go through Jeffrey Sambells blog!

Delphi 5 application partially loaded in task manager, takes forever to actually display

I have an application written in Delphi 5, which runs fine on most (windows) computers.
However, occasionally the program begins to load (you can see it in task manager, uses about 2.5-3 MB of memory), but then stalls for a number of minutes, sometimes hours.
If you leave it long enough, the formshow event will eventually occur and the application window will pop up, but it seems like some other application or windows setting is preventing it from initially using all the memory it needs to run (approx. 35-40 MB).
Also, on some of my client's workstations, if they have MS Outlook running, they can close it and my application will pop up. Does anyone know what is going on here, and/or how to fix it?
Since nobody has given a better answer I'll take a stab at how to solve this:
There's something in your initialization that is locking it up somehow. Without seeing your code I do not know what it is so I'll only address how to go about finding it:
You need to log what you accomplish during startup. If you have any kind of screen showing I find the window title useful for this but it sounds like you don't--that means you need to write the log to a file. Let it get lost, kill the task and see where it got.
Note that this means you need to cleanly write your data despite an abnormal program termination. How to go about this:
A) Append, write your line, close.
B) Write your line, then flush the file handle.
C) Initially write your file to consist of a large number of blanks--ensure this is larger than the actual log will be. Write your line. In case of abnormal termination it will retain the original larger file size.
I would write a timestamp on every log item so you can see if it's just processing something too slowly.
If examining the log shows you where the problem is, fine. If, as usually happens, it's not enough you put a bunch more logging between the last item that did get logged and the next one that didn't--I've been known to log every line when hunting a cryptic problem that only happened on someone else's system.
If finding the line isn't enough to pinpoint the problem also dump the value of relevant variables.
Finally, if such intense scrutiny makes the bug go away start looking for an uninitialized variable. (While a memory stomp is also an option I doubt it's the culprit here.)

Timer is being fired frequently in gwt which makes scrolling unresponsive when viewing it in an ipad

I am using GWT 2.4.
I am using Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() and Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() when needed.
For some reason, when I am debugging the website a timer fired event is being shown frequently even when I am in the login page(where I do nothing besides showing username and password).
Why is this happening? It is because of this, that the scrolling looks unresponsive.
Please note that I am remotely debugging the website by connecting my ipad to macbook.
Attached is a screen grab. Any help will be greatly appreciated.
When you say
a timer fired event is being shown frequently
Do you mean that the RepeatingCommand gets executed over and over ?
As soon as you call scheduleFixedDelay, the scheduler will execute the RepeatingCommand as long as the execute() method returns true.
I am in the login page
How about writing a log to see if the scheduled command you are talking about in the question gets invoked, even if you're not logged in ?
I found the reason for the delay. On each touch start I was getting all the text and applying a property like html.getElement().getStyle().setProperty("webkitUserSelect", "none") as part of my requirement. The data in that html is pretty big and to keep doing it on every touch start was causing a delay. Got rid of it now.

iOS touchesMoved delay between first and second calls

I have some problems in my iOS app.
I have checked timestamps in the touchesMoved with clock() function and use difference between current and previous values. Difference between 1st and 2nd events is greater than others.
Have you any ideas?
iOS is not a hard-realtime OS. There is generally no expectation that touch events will be delivered with regular frequency/uniform periods. You should not structure your app to depend on that. Events are delivered via the main thread, which could be delayed by other processing (drawing, etc.)
EDIT: If you're seeing huge differences in periods between the 1st and 2nd touches (relative to the periods between subsequent touch events), the first step would be to run the app in Instruments' Profiler template to see if some work that you're doing on the main thread in response to the first touch is causing the delay. If the delay is of your own doing, then fixing that is the first order of business.
Beyond that, you could try using various signal processing approaches to re-sample your data into uniform periodic data, but the problem is that any of those algorithms won't be able to deliver the first re-quantized point until at LEAST the 2nd (and more likely the 3rd or even later) event comes in, so if the principal problem is "The 2nd event doesn't come as soon as you'd like", then this won't help you.
Another good test: Try making an empty single-view sample app that does nothing but log the events as they come in -- if you see the same "odd" delay between 1st and 2nd touches in that trivial sample app, then that's just "how it is," and you can stop wasting time trying to change the OS behavior and move on to some different approach/solution.

How do I debug my program when it hangs?

I have an application which takes measurements every second (I am running it in demo mode & generating random data, so the problem is not to do with reading from devices attached to the serial port).
After 5 or 6 minutes it hangs.
I have added
try
// entire body of procedure/function goes here
except
on E: Exception do
begin
MessageDlg('Internal coding error in <function name>()',
mtError, [mbOK], 0);
end;
end;
to every single function (and Application.Run() in the project file), but I don't see any message dialogs. Any idea how I can test this?
Update: I woudl guess sit to be a resource problem, either RAM or MySql database - but other programs are running ok, and it's only 5 floats and timestamp that get saved with each measurement, so both seem unlikely after such a short time.
Solution: there were many great answers (thanks and +1 all round), but I finally got it (as suggested) by running in the IDE and using Run/Pause to see that it was an ever increasing loop.
Thanks again, everyone.
I'd try the following:
Attach and click Pause and see where it is, what threads are running, what threads are waiting (if all of them then you have a deadlock).
Refactor your main method into bunch of small ones (you may have already done that) and then replace small ones with dummy/hardcoded values. This may help but not necessarily identify faulty block.
Watch the system resource consumption (handles, threads, etc.) with PerfMon or something. See if you running out of memory and start using HDD.
If you using sockets, check if your reading timeout is set to infinity. If yes then change to some value and watch for timeouts.
In .NET it's possible to enabling handling of all exceptions, which means before the code handle it (like in catch statement), the IDE breaks at the point of the exception. Enable that in Delphi if possible and see if you are getting any.
Use the debugger to find out what your app is doing when it appears to hang.
Run your program under the debugger. Let it run until it hangs. When it hangs, switch to the debugger and select "Debug: Break All" (or equivalent) to make the debugger freeze all threads and take control of the process.
Now open the Threads view in the debugger and examine the stack traces of each thread in your program. Start with the main thread, obviously. Be sure to look back through the call stack for several calls to see if you recognize any of your code. If you find a stack trace that is in the middle of a loop, examine the local variables to see if your loop control variable has somehow slipped past the exit condition and put you into an infinite loop.
If your stack traces indicate that every thread is blocked waiting for some external event, you may have a thread deadlock - thread A taking lock A, then trying to take lock B, while thread B is holding lock B and trying to take lock A. If you're not using threads in your program, this is less likely but still keep an eye out for it.
If nothing odd jumps out at you after reviewing the stack traces of the threads, let the program run a few seconds more, then break into it again with the debugger and have another look around. See what's different in the stack traces.
This should help you narrow down at least which bodies of code are involved in your hang.
If you don't see an exception before adding the exception handlers, you won't produce any MessageDlgs to see.
If the program is hanging (rather than blowing up with an exception) you could have a looping problem, or you could have some blocking call that's never completing. Write log messages to a window or file (you can use OutputDebugStr) to isolate the problem to one section of your code — at least to the body of one function. You may see the problem right away. If not, you can use OutputDebugStr, breakpoints, and trace to learn what's happening in that section of code on a line-by-line basis.
First: try to debug it in Delphi IDE.
Second: if you can't do this (on customer PC), try the "Process Stack Viewer" of my (open source) sampling profiler:
http://code.google.com/p/asmprofiler/wiki/ProcessStackViewer
(you need some debug info: a .map or .jdbg file)
Then look at the stack of your threads (probably main/first thread). You can post the stack trace here then (if you can't find the problem).
If you want help with this sort of thing in an app that you cannot use the IDE for, then something like madExcept can help a lot. It has an automatic freeze checker for the main thread, and you can have it give you a stack dump to show what it was doing when it was frozen. The user can choose to kill or continue, and the app can tell madExcept it is busy and not to alert if appropriate (for doing long analysis or printing or something).

Resources