How to add a timing event - windows

Is there a way when I click on a ToolStripButton, it shows the WaitCursor and updates the StatusStrip for about 10 seconds, then returns back to normal. I just don't know how to type in the coding.
If someone could guide me through the process. (or even give me the code)
Thank You
J Mahone

Using a timer:
1:Add a timer from your component toolbox to your form.
2:Set the inteval to 10,000 (this is in milliseconds, 1000 = 1 second)
3:In the timers' "Tick" event, write this code:
Timer1.stop 'This assumes your timer it named Timer1
Me.Cursor = Cursors.Default
4: When you want to make it show the cursor, either have a method to do both these lines and call the method or just write these 2 lines all over the place:
Me.Cursor = Cursors.WaitCursor
Timer1.Start

I'd suggest to use async/await to keep the "normal" program flow.
Me.Cursor = Cursors.WaitCursor
Await Task.Delay(10000)
Me.Cursor = Cursors.Default

Related

THREE.Audio filter not ramping up with linearRampToValueAtTime

I'm having a little trouble working with the linearRampToValueAtTime on a BiQuadFilter applied to a WebAudio.
The audio works ok, and the initial lowpass filter is applied.
Problem is, as soon as I use the linearRamp method to bring up the frequency, it seems to ignore the endTime parameter (or better, it's not time correctly).
Some code to explain it better.
Here's the instancing:
this.audioLoader.load( 'public/media/soundtrack-es_cobwebs_in_the_sky.mp3', buffer => {
this.sounds.soundtrack = new THREE.Audio(this.listener);
const audioContext = this.sounds.soundtrack.context;
this.biquadFilter = audioContext.createBiquadFilter();
this.biquadFilter.type = "lowpass"; // Low pass filter
this.biquadFilter.frequency.setValueAtTime(200, audioContext.currentTime);
this.sounds.soundtrack.setBuffer(buffer);
this.sounds.soundtrack.setFilter(this.biquadFilter);
this.sounds.soundtrack.setVolume(0.5);
this.sounds.soundtrack.play();
})
Until here, everything looks ok. The sound plays muffled as needed.
Then, after a certain event, there's a camera transition, where I want the sound to gradually open up.
As a endTime parameter, I'm passing 2 seconds + the internal context delta.
this.sounds.soundtrack.filters[0].frequency.linearRampToValueAtTime(2400, 2 + this.sounds.soundtrack.context.currentTime);
Expecting to hear the ramp in two seconds, but the sound opens up immediately.
What am I missing?
The linear ramp will be applied using the previous event as the startTime. In your case that will be audioContext.currentTime at the point in time when you created the filter. If that is sufficiently long ago it will sound as if the ramp jumps right to the end value. You can fix that by inserting a new event right before the ramp.
const currentTime = this.sounds.soundtrack.context.currentTime;
const filter = this.sounds.soundtrack.filters[0];
filter.frequency.setValueAtTime(200, currentTime);
filter.frequency.linearRampToValueAtTime(2400, currentTime + 2);

Rxjs throttleTime - update the throttling in realtime?

Is there a way to update the throttleTime in Rxjs. You're scrolling near the bottom of the page, so we only need throttle every 400ms, while as you get nearer the top, we increate to 100ms as the target area is in that region
this.scrollSubscription$ = this.scrollSubject$
.asObservable()
.throttleTime(200, undefined, throttleTimeConfig)
.subscribe(event => this.throttledScrollHandler(event));
What I am going to do is have two separate subscripbtions, as I cannot find a way of doing it.
this.slowerSubscriber$ = this.scrollSubject$
.asObservable()
.throttleTime(400,.......
Thought I would ask as I can't think of another way of achieving it
You can use throttle to implement your own silencing duration:
// Make this function extract the position using scrollY, page offsets or whatever you want to use
const getScrollPositionFromEvent = event => 42;
this.scrollSubject$.asObservable()
.throttle(event => Observable.interval(
getScrollPositionFromEvent(event) <= 100 ? 100 : 400
))
.subscribe(console.log);
You can see a working example here. It simply emits by a given input, which in your case would be based on the scroll offset.

Swift: Repeat action after a random period of time

Previously, with Objective-C I could use performSelector: in order to repeat an action after a random period of time which could vary between 1-3 seconds. But since I'm not able to use performSelector: in Swift, I've tried using "NSTimer.scheduledTimerWithTimeInterval". And it works in order to repeat the action. But there is a problem. On set the time variable to call a function that will generate a random number. But it seems that NSTimer uses the same number every time it repeats the action.
What that means is that the action is not performed randomly, but instead, after a set period of time that is generated randomly at the beginning of the game and it is used during all the game.
The question is: Is there any way to set the NSTimer to create a random number every time it executes the action? Or should I use a different method? Thanks!
#LearnCocos2D is right... use SKActions or the update method in your scene. Here is a basic example of using update to repeat an action after a random period of time.
class YourScene:SKScene {
// Time of last update(currentTime:) call
var lastUpdateTime = NSTimeInterval(0)
// Seconds elapsed since last action
var timeSinceLastAction = NSTimeInterval(0)
// Seconds before performing next action. Choose a default value
var timeUntilNextAction = NSTimeInterval(4)
override func update(currentTime: NSTimeInterval) {
let delta = currentTime - lastUpdateTime
lastUpdateTime = currentTime
timeSinceLastAction += delta
if timeSinceLastAction >= timeUntilNextAction {
// perform your action
// reset
timeSinceLastAction = NSTimeInterval(0)
// Randomize seconds until next action
timeUntilNextAction = CDouble(arc4random_uniform(6))
}
}
}
use let wait = SKAction.waitForDuration(sec, withRange: dur) in your code. SKAction.waitForDuration with withRange parameter will compute random time interval with average time = sec and possible range = dur
Generate a random time yourself and use dispatch_after to do the action.
For more information on dispatch_after, see here. Basically you can use this instead of performSelector

How would you use events with Selenium 2

How would one click on a button, wait for an event like blur and then get the pagesource of the site?
I know i can use the getPagesource() method, but I only wanna do this after a jquery loading image has been shown.
If the blur event results in a visible effect, you could wait for that effect, like waiting for an image to be shown.
Otherwise, if there is no visible effect from that event, you would need a "testing hook" to tell your test that the function associated with that event already ran, like a javascript variable being set to a known value that you could query in the test.
For both cases you could use an explicit wait for the condition, like what is shown in the documentation:
http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits
EDIT:
Regarding your comment, Nyegaard, you could use an explicit wait like this one:
WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
Boolean expectedTextAppeared =
(new WebDriverWait(driver, 10))
.until(ExpectedConditions.textToBePresentInElement(
By.id("ctl00_content_createnewschema_modalAlert_alertMessage"), "textYoureExpecting"));
This code will wait for "textYoureExpecting" to appear in the span with a timeout of 10 seconds. If it takes more time for it to appear, you just need to adjust the timeout.
For all AJAX requests in the webpage I use jQuery.Active flag to determine if the page is loaded or not. If jQuery.Active is non-zero that means those are the number of active requests the browser is dealing with. When it comes down to zero, that means number of active requests are none. I haven't used this flag for blur events, but you might as well give it a try. You should definitely use implicitly and explicitly waits Luiz suggested. Here is a function that waits for 5 minutes for active requests to complete. You could perhaps parameterize that, add try, catch etc.
public int waitforAJAXRequestsToComplete(){
long start = System.currentTimeMillis();
long duration;
boolean ajaxNotReady = true;
while(ajaxNotReady){
if(((JavascriptExecutor)driver).executeScript("return jQuery.active").toString().equals("0"))
return 0;
duration = System.currentTimeMillis() - start;
duration = (long) (duration/(60*1000F));
if(duration>5.0)
return 1;
}
return 1;
}

Should I use Ajax Timer?

I want to have a stopwatch on the site, which displays running time on the label without reloading a page. Is it possible to do this on client side? Should I use Ajax timer or smth else from .net?
Website is in C#.
Some links or demos would be really helpful ! Thanks !
You can do this with basic JavaScript using setTimeout:
var totalSeconds = 0
function stopwatch() {
// increment the seconds
totalSeconds++;
// display the seconds to the user
document.getElementById("<%=myLabel.ClientID%>").innerHTML = "You have spent " + totalSeconds + " on this page.";
// wait a second and call the timer again
setTimeout("stopwatch()", 1000);
}
// trigger the timer
timer();
Update: If the user is going to be on the page for a while you probably want to display a slightly more user-friendly message then "You have spent 1000 seconds on this page". Here's a quick JavaScript function that'll transform the seconds into time elapsed.
It is possible to do in javascript only. There are so many example out there. Just google them. Here's one.

Resources