timing a method's duration - objective-c

I have a splash that displays at my app's startup while it loads data from a Web query. I'd like to make sure the splash displays for at least 3 seconds, but sometimes the load query takes less than this. However, I don't want this 3 seconds added to the time it takes to load the web data; I just want to make sure the minimum is 3 seconds.
In other words, can I time how long it takes to load the data, then maybe set a delay for the difference between that load time and 3 seconds, and make the splash hang on (using a selctor or something) for that extra amount of time?

I'd suggest that instead of doing it that way, you start a 3 second long timer when you start the load query. When each finishes, set a boolean to say that one finished and call a method that checks if both are done yet; if so, it's time to close the splash window. (sorry, no code examples - I'm not familiar with Objective C)

Related

Can I pause Cucumber/Selenium JS execution while it waits for longer time?

I have a scenario like this
Scenario: Long Wait
Given I Make some changes on webpage
When I wait at least 10 mins for changes to take effect
Then I can see the changes took effect
The step 2 is of course solvable by waiting 10 minutes, but those are 10 minutes I'd rather spend testing other scenarios which don't interfere with the changes made.
Is there a way to run specific scenarios in the 10 min gap, and then resume the original scenario? Something like
Execute the Long Wait scenario
Once it gets to step 2, pause this scenario
Run scenarios from the non-interfering pool
Wait until 10 minutes are up
Finish the non-interfering scenario that is currently running
Resume the original Long Wait scenario

ASP.NET pages lag intermittently

I'm using IIS 10, SQL Server 14, and .NET 4.5. I have made a website with just 4 pages of significance. Any one of them loads perfectly, every time. And quickly, even though they do a lot of work with datatables and database edits.
But if I open two browser windows (same session if it matters) and play around for a while loading pages in one window while the other is refreshing another of the pages every 3 seconds, it is only a matter of time until they freeze up for a bit. Sometimes only for 5 or 10 seconds. Often for over a minute, and sometimes for as long as 20 minutes.
What I've tried:
My first thought was SQL deadlock and I spent a long time down that rabbit hole. All my select statements now use WITH (NOLOCK). I've run SQL profiler, and there is no discernible rhyme or reason to which queries have long durations during these periods, and none are that long. The longest "StartTime - EndTime" on the trace is never more than 0.25 seconds. I added my own StopWatch control to my functions that do my cmd.ExecuteNonQuery() statements and another on the one that gets my datatables, and see the same thing: max elapsed times during the hangs of 250ms or thereabouts. Under "normal" lag/hang-free operation, the elapsed times typically record 0ms, and at most maybe 3ms. The jump of 100x during the hang is confusing and concerning, but don't at all account for the long periods of lag/hang. And each time this happens, it will only be 1 or 2 statements with that extended duration.
I turned my attention to debugging the page that refreshes every 3 seconds. I use a StopWatch there also, and the page always loads in under 3ms as measured from the first line of the form_load event to the last line of the form_unload event. What is interesting here, is that while it is hung, it sure LOOKS LIKE Chrome (my browser) is trying to load the page. The little circle is spinning, and it is just waiting. It never times out, even if it takes 20 minutes. But during that time it will never record the first debug entry of form_load. Once it finally resolves, it will run the page as well as ever. So in my log I'll see something like this (oldest entry at the bottom):
2021-02-07 11:52:21.703 unload
2021-02-07 11:52:21.700 load
2021-02-07 11:52:18.642 unload
2021-02-07 11:52:18.640 load
2021-02-07 11:50:37.820 unload
2021-02-07 11:50:37.817 load
2021-02-07 11:50:34.777 unload
2021-02-07 11:50:34.773 load
Note how the page loads quickly every time, and while there is normally a 3 second gap between loads, in one case there was almost a 2 minute gap.
Looking at my W3SVC1 logs, and lining it up to that same time, I see that there are entries (both POST and GET) for the pages with time-taken of around 90000 (not sure what units on that) where the entries before and after the problem are mostly in the 10-50 range.
I'm at a loss of what to look at next.

ASP.NET MVC page slow Time To First Byte

I have two views that I am refreshing every few seconds asp.net mvc. Every few views are refreshed since there is another program that is updating the database. It is taking a lot of time and it is random, what I mean by that is sometimes the first view reload time is slow and sometimes the second view reload time is slow. It is in 500ms or 50ms each for view1 and view2 or vice versa 500ms for view2 and 60ms for view1. I needs to reduce both the load time to 10ms. I have set the timer interval to 30 seconds and loading the views. I did sql profiler to see if the queries are taking a long time and it does not look like it. In dev tools TTFB time is showing as taking long and this is on my local machine with local webserver and sql. Please advise!
Thanks

Can a WinRT background task be long-lived if within CPU and Network limits?

Microsoft's documentation states:
Background tasks are meant to be short-lived tasks that do not consume a lot of resources.
It also says:
Each app on the lock screen receives 2 seconds of CPU time every 15 minutes, which can be used by all of the background tasks of the app. At the end of 15 minutes, each app on the lock screen receives another 2 seconds of CPU time for use by its background tasks.
I need to run a background task every two minutes to update my live-tile.
My app is a lock-screen-app.
Computation is within the CPU and network usage constraints
Can I create a permanent background task (e.g. something which polls a web service and pulls information, waits and loops) to create a OneShot TimeTrigger every two minutes or is there a better way of doing this?
My concern with the background task option is whether the runtime would deem the task inactive while it was sleeping and close it or something else like there's a limit on the number of times a live tile can be updated within 15 minutes...
Yes, if by long lived you mean under 25 minutes.
Time triggers cannot execute more frequent than 15 minutes. Creating a OneShot trigger that executes in 2 minutes is, that's an interesting idea and should work. Yes, background tasks can register other background tasks to keep this chain going. Should the user's machine be off when it execs it will queue later.
Having said that, updating your tile that frequently & using a background task is not a wise solution. Because, it is unreliable. Background tasks can be disabled, for one. But every 15 minutes, you are going to exceed your quota. Try using a Scheduled tile instead.

How to terminate code that takes long in vb.net?

How to terminate function/code (not entire page) when it takes some time, for example, more than 1 sec?
If Code > 1 Sec Then
Terminate the code....
I found the command "Server.ScriptTimeou", but it stops the entire page instead of one command.
You can run your function in a background process and start a timer simultaneously. Then abort the process if it runs more than 1 second.
If you want to run in the foreground then you probably have a loop somewhere that is taking a long time. Before you start running, save the current time. Then, somewhere in the middle of the loop, compare the saved time to the current time. When it hits one second, break out of the loop.
The solution will depend on what you're doing. If you're calling a single function that you have no control over and that can sometimes run longer than 1 second or so, you're pretty much stuck with having to run that function on a background thread and then terminate the thread if it runs long.
If you're actually running a long loop, or some other code that you DO have control over, you could just note the current time before starting the process, and in the loop, check if you've run long, and if so, exit the loop.
Just depends.