I have a program that displays a UI
, allows the user to pick virtual machine names obtained by querying the Xen
pool master server, and then creates snapshots for the selected virtual machines. I want the snapshots to be created in the background so I can keep the UI
responsive and update the UI
with progress as each snapshot is created.
Originally, I connected to the Xen
pool master server and then executed the Xen
create snapshot cmdlet once per selected VM in the UI
thread. As such, the UI
became unresponsive.
Next, I connected to the Xen
pool master server and then did a start-job
(background job
) once per VM to create the VM's snapshot. This failed because the Xen
session created in the UI
thread could not be passed to the background job
(The content of the session variable makes it into the block, but the Xen Connect
cmdlet in the block returns a Could not find open sessions to any XenServers
error).
Then, I moved connecting to the Xen
pool master server into the background job
. This slowed operations because the making the connection takes a few seconds and was being done once for each VM. However, the UI
remained responsive and I was able to use job completion data to update the UI
.
How can I keep the UI
responsive, update the UI
with progress as each snapshot is created, and not be forced to connect to the server once per snapshot?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…