我正在開發一個SCVMM 2012控制檯插件。SCVMM 2012控制檯插件執行
SDK文檔可以在這裏找到:http://msdn.microsoft.com/en-us/library/jj860311.aspx
但文檔有螺紋或如何外接得到根本沒有執行信息。
現在,這裏是我有:
public class SomeAddIn : ViewAddInBase
{
private bool gotServerInfo = false;
private bool gotConnectionString = false;
public override FrameworkElement CreateViewControl()
{
GetServerInfo();
GetConnectionString();
if(gotServerInfo && gotConnectionString)
{
return GetGoodFrameworkElement(); //do some stuff to fill FrameworkElement
}
MessageBox.Show("Can't connect to DB, returning empty screen...");
return new FrameworkElement();
}
private void GetServerInfo()
{
PowerShellContext.ExecuteScript<ServerConnection>("Get-SCVMMServer localhost",
(items, error) =>
{
// code to set server info here
if (error == null)
{
gotServerInfo = true;
MessageBox.Show("Got settings from server.");
}
else{//Error}
});
}
private void GetConnectionString()
{
//PowerShell connect to database, get connection string
gotConnectionString = true; //if got string
}
}
看起來一切都很好,但問題是,powershell
命令需要時間來執行,且「return new FrameworkElement();
」被執行之前,首先gotServerInfo
和gotConnectionString
獲得設置爲true。
我的猜測是VMM爲我的方法啓動多個線程,並且這些線程的執行不再是順序的。如何讓VMM以正確的順序執行我的方法?
我已經嘗試做的事:
1)使用線程我的方法,設置優先級高,設置當前 線程優先級爲低,甚至爲背景,然而,這並沒有幫助。 Thread.Join也不起作用。
2)移動我的方法爲「public override void OnLoad()
或 OnShow()
該CreateViewControl()
被執行第一反正。
任何想法?