2011-08-08 52 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