2016-05-02 15 views
-1

Ich arbeite an einem asp.net mvc5 Projekt und ich möchte Chatroom mit SignalR implementieren So habe ich Microsoft.Aspnet.SignalR von nuget und ich habe eine SignalR Hub-Klasse für Hub und jetzt ich möchte OnDisconnected() -Methode außer Kraft zu setzen .aber ich Fehler bekommen ‚ChatHub.OnDisconnected()‘: keine geeignete Methode außer Kraft zu setzen
fand ich weiß nicht, wie dieses Problem zu lösen, bitte helfen Sie mirwie man SignalR Methoden in mvc 5

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using Microsoft.AspNet.SignalR; 
using System.Collections.Concurrent; 
using System.Threading.Tasks; 

namespace WebApplication3.Hubs 
{ 
    public class ChatHub : Hub 
    { 
     public void Hello() 
     { 
      Clients.All.hello(); 
     } 
     static ConcurrentDictionary<string, string> dic = new ConcurrentDictionary<string, string>(); 

     public void Send(string name, string message) 
     { 
      Clients.All.broadcastMessage(name, message); 
     } 

     public void SendToSpecific(string name, string message, string to) 
     { 
      // Call the broadcastMessage method to update clients. 
      Clients.Caller.broadcastMessage(name, message); 
      Clients.Client(dic[to]).broadcastMessage(name, message); 
     } 

     public void Notify(string name, string id) 
     { 
      if (dic.ContainsKey(name)) 
      { 
       Clients.Caller.differentName(); 
      } 
      else 
      { 
       dic.TryAdd(name, id); 
       foreach (KeyValuePair<String, String> entry in dic) 
       { 
        Clients.Caller.online(entry.Key); 
       } 
       Clients.Others.enters(name); 
      } 
     } 
     public override Task OnDisconnected() 
     { 
      var name = dic.FirstOrDefault(x => x.Value == Context.ConnectionId.ToString()); 
      string s; 
      dic.TryRemove(name.Key, out s); 
      return Clients.All.disconnected(name.Key); 
     } 
    } 
} 

Antwort

0

Für SignalR 2.1.0+ , müssen Sie OnDisconected(bool stopCalled) verwenden.

// Microsoft.AspNet.SignalR.Hub 
// Summary: 
//  Called when a connection disconnects from this hub gracefully or due to a timeout. 
// 
// Parameters: 
// stopCalled: 
//  true, if stop was called on the client closing the connection gracefully; false, 
//  if the connection has been lost for longer than the Microsoft.AspNet.SignalR.Configuration.IConfigurationManager.DisconnectTimeout. 
//  Timeouts can be caused by clients reconnecting to another SignalR server in scaleout. 
// 
// Returns: 
//  A System.Threading.Tasks.Task 
public virtual Task OnDisconnected(bool stopCalled);