Scope
This applies to users who change variable values on their PowerShell Universal environments during runtime. This affects all versions of PowerShell Universal.
Problem
Apps and APIs will restart when variables are changed. This can cause users to lose work and appear they have been disconnected from apps. It can cause APIs to lose cache data.
Root Cause
This behavior is currently by design. When runspaces to execute PowerShell are created in PowerShell Universal, variables are set to their values. Instead of reading the variable values during each execution, the variables are present in the default state of the runspace. This provides a performance increase since the variables do not need to be set with every execution. When variables change, PowerShell Universal will restart processes or recycle runspace pools to populate the runspace with new variable states. This causes apps and the API processes to restart.
Workaround
To work around this issue, you can do the following.
Apps
Disabling auto reload on apps will prevent this from happening. Do note, new variable values will not be reflected in apps until they are restarted.
APIs
The issue with APIs is that they may lose cached data stored in the $Cache scope. Typically, APIs do not maintain state but the $Cache scope is an exception. To avoid losing data, use Set-PSUCache instead. This stores cached data within the server and will survive restarts of the API service.