Hello,
I am using the VirtualBox API "IProgress::waitForCompletion()" and as a parameter I am passing it "-1" to wait for indefinite time. Is there a way to check when the process/task is completed, by some sort of flag or interrupts?
Thanks
How to get notification for Completed task
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: How to get notification for Completed task
Sadly, there isn't any callback or event listener available.
You will need to setup a dedicated thread waiting short amount of time (typically between 100 and 500 ms) to handle waiting and create custom events/callback when the progress amount changes.
This is especially important since you also need to process the event queue meanwhile.
You will need to setup a dedicated thread waiting short amount of time (typically between 100 and 500 ms) to handle waiting and create custom events/callback when the progress amount changes.
This is especially important since you also need to process the event queue meanwhile.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
Re: How to get notification for Completed task
What if I try to get the values of following attributes from IProgress - percent, timeRemaining and completed, would I be able to achieve my objective?
Basically what I am trying to do is delete the Virtual Machine, and I am waiting indefinitely till the machine is Deleted (but on a custom UI I have to show a progress bar, so to display the progress bar/or a message on successful operation I need those events).
Here is the small snippet of the code that I have written, just for reference -
Basically what I am trying to do is delete the Virtual Machine, and I am waiting indefinitely till the machine is Deleted (but on a custom UI I have to show a progress bar, so to display the progress bar/or a message on successful operation I need those events).
Here is the small snippet of the code that I have written, just for reference -
Code: Select all
IMachine *machine = NULL;
IProgress *progress = NULL;
long rc = machine->Unregister(mode,&resourceArray);
if (!FAILED(rc))
{
rc = machine->DeleteConfig(resourceArray,&progress);
if (!FAILED(rc))
{
rc = progress->WaitForCompletion (-1);
}
else
{
//do something
}
}
else
{
//do something
}
Last edited by socratis on 23. Nov 2016, 07:14, edited 1 time in total.
Reason: Enclosed the information in [code] tag for better readability
Reason: Enclosed the information in [code] tag for better readability
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: How to get notification for Completed task
So something like this (pseudo-java example):noteirak wrote:You will need to setup a dedicated thread waiting short amount of time (typically between 100 and 500 ms) to handle waiting and create custom events/callback when the progress amount changes.
Code: Select all
IMachine machine = vbMgr.getVBox().findMachine(uuid);
try {
List<IMedium> hdds = machine.unregister(CleanupMode.DetachAllReturnHardDisksOnly);
IProgress p = machine.deleteConfig(hdds);
while (!p.getCompleted() || p.getCanceled()) {
try {
Thread.sleep(500); // 500ms, but you can set anything you like here, even adapt depending on remaining time to have a more dynamic update
produceProgressUpdateEvent(p); // create your own custom event here to update your UI accordingly
} catch (InterruptedException e) {
Logger.exception(e);
}
}
if (p.getResultCode() != 0) {
throw new MachineException(p);
}
} catch (VBoxException e) {
throw ErrorInterpreter.transform(e);
}
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!