Is there a relatively easy way to include a custom 'OnStart()' in every script I create?
My use case:
I am often using Html controls to build UIs in Linqpad. I understand that when I don't use Util.KeepRunning(), breakpoints in the debugger won't be hit in things triggered by events, because the main thread has already ended at this point, and all subsequent event handlers are running in separate threads.
I did a quick experiment where I added:
void OnStart()
{
if (Debugger.IsAttached)
Util.KeepRunning();
}
and as long as I have the 'Break when exception is unhandled' box checked on my query, this does what I need.
I was thinking I'd just like that piece of code to be automatically included in all new scripts I create. I was talking to Claude Sonnet about this and it appears to have hallucinated that such a 'template script' feature exists in Advanced, but I don't see it... so, thanks Claude. ![]()
Curious if anyone else has these kinds of slight annoyances and if they have any suggestions for what I'm sort of trying to accomplish. Likely the best thing is to just add a snippet and remember to use it for UI scripts.
Answers
-
Does the "Set as default for new scripts" only apply package references and other configuration for the script only, and not code? I could have sworn that was a thing.
Other ways to quickly add this would be to add the
OnStart()method to a small script that you would then#loadin. Or perhaps a snippet that gives you quick access to it. Or both? -
The best you can do right now is to put that code into a script and
#loadit. You can create a shortcut to insert the #load via a snippet (right-click, Save as Snippet).
