2011-08-08 54 views
0

我想,當你關閉應用程序Silverlight的退出調用Web服務

public App() 
     { 
      this.Startup += this.Application_Startup; 
      this.Exit += this.Application_Exit; 
      this.UnhandledException += this.Application_UnhandledException; 
      InitializeComponent(); 
     } 

private void Application_Exit(object sender, EventArgs e) 
     { 
      ClientReverse.UserExitGameAsync((Guid)Login); 
     } 

服務器將數據發送到服務器:

public void UserExitGame(Guid UserGuid) 
     { 
      Games.Games.ExitUserGames(UserGuid); 
     } 

但服務器端並不滿意。

回答

1

到達ApplicationExit事件時已經太晚了。

我看過Javascript,它一直保留在網頁上直到確認(Stack Overflow做了很多)。您可能希望修改該版本的Javascript,該版本在允許頁面關閉之前將消息發送回Silverlight應用程序。從JS調用Silverlight方法很容易(您可以簡單地將SL方法暴露給JS,並使用[Scriptable]屬性)。

+0

因爲silverlight正在調用WCF,爲什麼不直接調用HTML中的onbeforunload並使用ajax調用WCF而不是silverlight? – Rumplin

+1

@Rumplin:這也是有效的,但我看到很多關於'onbeforeunload'的故事不適用於所有瀏覽器。歌劇顯然不會解僱它。 –

+0

好吧,不知道,因爲我主要在IE和Silverlight的封閉環境(Intranet)中工作。謝謝你的提示。 – Rumplin