Replaced OnDemand Links don't always work if displayed more than once.
I have a script which contains links to execute an external program and then replaces the link with another link to display the results. The initial link always works, but sometimes the replaced link would not work.
From debugging, it looks like if the replaced link is displayed twice, the first link does not work.
The following program illustrates the issue
void Main(string[] args) { Util.KeepRunning(); var array = new Test[] { new Test("A"), new Test("B")}; array.Dump(); array.Skip(1).Dump(); } public class Test { public string Name ; public DumpContainer Link; public Test(string name) { this.Name = name; Link = Util.OnDemand<DumpContainer>("DoIt", () => DoIt(this)); } DumpContainer DoIt(Test rs) { return Util.OnDemand("Click here to see results", () => { return "The Results"; }); } }
Run the script and click on the two links in the first grid and they both work correctly.
The replaced link works for A but not for the B in the first grid and the status line just says 'Executing action ...'
The replaced link for B in the second grid does work.
Now I know what causes this, I can work around it by scrolling down to find the last link for that record which will work.
Comments
Until.OnDemand()
replaces the link with the contents of the factory function when clicked on. Since the links are part of the state of the object, it remains in its expanded state if you had dumped it earlier.Rather than putting the state in the object, define a
ToDump()
function for the type to then create the on demand call. Just note, that this will make each dump of an object independent of other dumps of the same object which may or may not be what you want.Hopefully I'm understanding your question correctly. All the links as dumped seems to function for me. Only clicking on the B link opens both copies that were dumped.
Thanks. That works better