[CA-211267] Add a null check, use Run() to stop child classes directly calling InitialiseTicker()

TickUntilCompletion() is now a static method and again takes an ApplianceAction parameter. It does a null check on each while iteration to handle the case where another thread nulls the action. Also added Run() method to ApplianceAction which initialises the ticker (now a private method), and let child classes call Run() instead.
This commit is contained in:
Callum McIntyre 2016-10-24 11:59:28 +01:00
parent 15b4705942
commit 7d7a040335
4 changed files with 16 additions and 14 deletions

View File

@ -82,6 +82,12 @@ namespace XenAdmin.Actions.OVFActions
Host = Helpers.GetMaster(connection);
}
protected override void Run()
{
SafeToExit = false;
InitialiseTicker();
}
protected void UpdateHandler(XenOvfTranportEventArgs e)
{
if (!string.IsNullOrEmpty(e.Message))
@ -101,16 +107,16 @@ namespace XenAdmin.Actions.OVFActions
m_transportAction.Cancel = true;
}
protected void InitialiseTicker()
private void InitialiseTicker()
{
System.Threading.Tasks.Task.Run(() => TickUntilCompletion());
System.Threading.Tasks.Task.Run(() => TickUntilCompletion(this));
}
private void TickUntilCompletion()
private static void TickUntilCompletion(ApplianceAction action)
{
while (!IsCompleted)
while (action != null && !action.IsCompleted)
{
OnChanged();
action.OnChanged();
Thread.Sleep(SLEEP_TIME);
}
}

View File

@ -90,11 +90,10 @@ namespace XenAdmin.Actions.OVFActions
protected override void Run()
{
SafeToExit = false;
base.Run();
var session = Connection.Session;
InitialiseTicker();
var url = session.Url;
Uri uri = new Uri(url);

View File

@ -76,9 +76,7 @@ namespace XenAdmin.Actions.OVFActions
protected override void Run()
{
SafeToExit = false;
InitialiseTicker();
base.Run();
if (m_verifySignature)
{

View File

@ -70,10 +70,9 @@ namespace XenAdmin.Actions.OVFActions
protected override void Run()
{
SafeToExit = false;
Debug.Assert(m_vmMappings.Count == 1, "There is one VM mapping");
base.Run();
InitialiseTicker();
Debug.Assert(m_vmMappings.Count == 1, "There is one VM mapping");
string systemid = m_vmMappings.Keys.ElementAt(0);
var mapping = m_vmMappings.Values.ElementAt(0);