I have loop for:
for (int i = 1; i < 2000; i++)
How I can change this loop that instead of int < 2000 I can get time:
for (int i = 1; i < 2000(miliseconds); i++)
I want to do this loop until time is less then 2000 miliseconds.I mean that this loop must working for 2 seconds and after 2 sec break.
In loop I doing some operations. I save position of cursor. I want save that position for 2 seconds.
Assuming you want to do something in a loop until 2000ms has passed:
[Edit] As commenter @CheJami points out, there’s no need to create a Date object since you can get the current time in milliseconds directly:
This strategy will likely result in better performance overall since there is no need to repeatedly create new objects and eventually garbage collect them.