2009-04-27 7 views
1

무겁게 javascripted 될 Silverlight 응용 프로그램을 만들고 있습니다. 이것은 자바 스크립트와 같이,Javascript/Silverlight 프록시 이중로드 지연

public App() 
{ 
    this.Startup += this.onStartup; 
    this.Exit += this.Application_Exit; 
    this.UnhandledException += this.Application_UnhandledException; 

    InitializeComponent(); 

    // register javascript bridge proxy 
    // (must register in constructor so proxy is available immediatly) 
    HtmlPage.RegisterScriptableObject("JsProxy", new JavaScriptProxy()); 
} 

그러나 :

, 내가 만든 다음 SL 클래스 JS 상호 작용을 활성화하려면 :

[ScriptableType] 
public class JavaScriptProxy 
{ 
    private string _version; 

    // provided for testing SL-JS integration 
    [ScriptableMember] 
    public void SmokeTest() { HtmlPage.Window.Alert("Hello world!"); } 
} 

을 그리고 주요 SL 응용 프로그램의 생성자에로드 - 무거운 애플 리케이션, 그것은 자바 스크립트 자체를 통해로드 할 수 있어야합니다.

e.e. 뭔가 alongs는 : agApp.Content.JsProxy는 실버 onLoad 이벤트가 트리거 될 때까지, 따라서 JsProxy 필드를 사용할 수없는 완전히 사용할 수 없기 때문에

// called on body.onLoad 
function init() { 

    var proxy; 

    var el = document.getElementById("target_canvas"); 

    Silverlight.createObject(..., el, "agApp" ..., { 

     onLoad: function() { 
      proxy = agApp.Content.JsProxy; 

      // ***this line is ok*** 
      proxy.SmokeTest(); 
     } 

    });   

    // ***this line fails (of course)*** 
    proxy.SmokeTest(); 

} 

그러나이 오류를 올립니다. 내가 실버 인스턴스를 만들 때

어떻게 JsProxy 클래스 즉시에 액세스 할 수 있도록 할 수 있습니까? 어떤 일이있는 동안 while (_mutex); 아마도 나쁜 생각 일 것입니다.

실버 라이트 앱 인스턴스 생성시 다른 추상화 계층이있을 것이므로이 기능을 사용하여 모든 SL 콘텐츠를 한 번에 동 기적으로로드해야합니다.

답변

1

이것은 Silverlight 때문이며 JavaScript는 별도의 스레드에서 작동합니다. 브라우저에 Silverlight 컨트롤을로드하도록 요청 했더라도 Silverlight가로드를 끝내기 전에 기다리지 않고 다음 줄로 진행합니다.

Silverlight에서 인스턴스화 한 후에 만 ​​JS 프록시에 액세스 할 수 있으므로 OnLoad 이벤트가 발생하기를 기다리거나 (Silverlight.xap 전체가로드 된 후에 만 ​​실행됩니다.) 또는 RegisterScriptableObject fire a onYourJSProxyNameLoaded()라는 자바 스크립트 메소드는 원하는 워크 플로우로 인라인으로 다시 돌아 가게합니다.

HTH.

- Scott Barnes/Rich Platforms 제품 관리자/Microsoft.