Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
IsAlwaysDirty functions not recalculating
posted

Hi,

I'm trying to add a custom UltraCalcFunction (GetPrice) that's able to poll periodically for price updates based on an investment identifier in another column. The investment identifier isn't changing, but I need GetPrice() to evaluate periodically anyways in case the price in the price provider has changed.

I thought I could do this by overriding AlwaysDirty to always return true. But it appears that even if a function is AlwaysDirty, it doesn't always get recalculated on the next ultraCalcManager.ReCalc() run.

I've attached a small project that demonstrates the problem. To test this, I'm using the built-in now() function as well as a custom CurrentTime() function that basically returns DateTime.Now. The properties on the UltraCalcManager are all default (asynchronous calculations, freq=10 ms, duration=50ms).

Letting the application sit and run doesn't update either unbound column as I would have expected (since the calc manager should be recalcing every 10 ms). Explicitly calling UltraCalcManager.ReCalc() doesn't do anything either. I have to explicitly DirtyAllFormulas before calling ReCalc for it to work. DirtyAllFormulas is prohibitively expensive for my application because there're many other formulas that should not be dirtied.

Interestingly, changing the sort order triggers an update of the timestamps, but only the first time I change the sort order.

 

Separately from the above issue where IsAlwaysDirty doesn't seem to really make formulas dirty, I would appreciate any advice you have on how I can periodically poll. Let's say that I only want to poll using GetPrice() every 5 minutes. But I have other formulas that need to respond at a much higher freqency. So I can't just adjust the UltraCalcManager's frequency setting. If IsAlwaysDirty worked as I expect, I would be hammering my price provider many times every second.

I was thinking of tracking the last evaluation time and comparing that to the current time to determine if I should actually do anything in Evaluate. But that doesn't work because every call of Evaluate is made independently and I have no way of knowing that the last evaluation time was for my cell or for a different cell.

Then I thought of trying to check to see if the current time falls into the couple of seconds after the start of an arbitrary 5-minute interval. If so, I poll. Otherwise, I have to return some sort of cached result. I would prefer to not have to set up result caching and just abort the Evaluate, leaving the current value as is. But it appears that I have to always return something, so caching is the best solution that comes to mind.

The problem with the above approach is that if, for whatever reason (other calcs taking a long time?), the calcmanager's misses the small window where polling should occur, you're stuck waiting for another 5 minutes before another window opens. This seems unreliable. Lengthening the window might help, but that also increases the duration under which we're hammering the price provider.

Any suggestions?

Thanks in advance,

-- Yale