[CA-211267] Add a lightweight polling mechanism to the appliance tasks, to provide an accurate timer

For other actions we get a ticking timer in the Events view because they use PollToCompletion, which calls their Changed event every 900ms. These actions don't use PollToCompletion, and didn't regularly call their Changed event - so their timer didn't tick regularly. This change adds a lightweight mechanism to call their changed event every 900ms until they complete. This allows the events page timer to tick every second in the same way as it does for other actions.
This commit is contained in:
Callum McIntyre 2016-10-21 14:45:35 +01:00
parent 5cb4cc8ba1
commit de43761039
4 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,7 @@
* SUCH DAMAGE.
*/
using System.Threading;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAPI;
@ -97,5 +98,23 @@ namespace XenAdmin.Actions.OVFActions
if (m_transportAction != null)
m_transportAction.Cancel = true;
}
protected void InitialiseTicker()
{
System.Threading.Tasks.Task.Run(() => TickUntilCompletion(this));
}
private void TickUntilCompletion(ApplianceAction action)
{
int sleepTime = 900;
while (!action.IsCompleted)
{
action.OnChanged();
Thread.Sleep(sleepTime);
}
}
}
}

View File

@ -92,6 +92,9 @@ namespace XenAdmin.Actions.OVFActions
{
SafeToExit = false;
var session = Connection.Session;
InitialiseTicker();
var url = session.Url;
Uri uri = new Uri(url);

View File

@ -77,6 +77,9 @@ namespace XenAdmin.Actions.OVFActions
protected override void Run()
{
SafeToExit = false;
InitialiseTicker();
if (m_verifySignature)
{
Description = Messages.VERIFYING_SIGNATURE;

View File

@ -73,6 +73,8 @@ namespace XenAdmin.Actions.OVFActions
SafeToExit = false;
Debug.Assert(m_vmMappings.Count == 1, "There is one VM mapping");
InitialiseTicker();
string systemid = m_vmMappings.Keys.ElementAt(0);
var mapping = m_vmMappings.Values.ElementAt(0);