2014-02-27 44 views
1

我正在開發一個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();」被執行之前,首先gotServerInfogotConnectionString獲得設置爲true。

我的猜測是VMM爲我的方法啓動多個線程,並且這些線程的執行不再是順序的。如何讓VMM以正確的順序執行我的方法?

我已經嘗試做的事:

1)使用線程我的方法,設置優先級高,設置當前 線程優先級爲低,甚至爲背景,然而,這並沒有幫助。 Thread.Join也不起作用。

2)移動我的方法爲「public override void OnLoad()OnShow()CreateViewControl()被執行第一反正。

任何想法?

回答

0

不要初始化過程中出現的問題的解決方案,但我轉移到MVVM (WPF)和一個單獨的線程模型,當你獲得基本的接口後,你想要做什麼以及如何同步所有的東西,VMM後者是一個常用的WPF應用程序,給你一個接口的主線程。 ThreadPool類用於調度後臺任務 - 發現它是最簡單的方法。