Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linqpad not resetting static variables between runs unless the code changes

Tags:

linqpad

Let's say I write this little linqpad snippet and run it, I get what I expect

enter image description here

But when I hit F5 again, the list will have two items in it:

enter image description here

I was not expecting it to do this and can't figure how why it would.

The list will be growing everytime I run it unless I do something to the code, even add a comment. Then it will reset to one entry.

Is this by design? If so why? I'm on 5.08.01

like image 388
Matt Avatar asked Sep 29 '16 00:09

Matt


1 Answers

It is by design. It does not reset the Application Domain unless you do one of the following:

1) Use Ctrl+Shift+F5 to reset it on demand

or

2) Go into Edit/Preferences/Advanced and set "Always use Fresh Process per execution" to True. This will reset every time you run a script

or

3) Put the following code into your query (this tells LINQPad to use a fresh domain next time you run):

Util.NewProcess = true;

As for why, there are probably multiple benefits but I'd say performance is the main one. You could put the results of an expensive query in a static variable and only run it the first time.

like image 117
dazedandconfused Avatar answered Sep 28 '22 01:09

dazedandconfused