2016-05-02 1 views
-1

Je travaille sur un projet asp.net mvc5 et je veux implémenter chatroom avec signalR J'ai donc obtenu Microsoft.Aspnet.SignalR de nuget et j'ai utilisé une classe SignalR Hub pour hub et maintenant Je veux remplacer OnDisconnected méthode() .mais j'obtiens l'erreur 'ChatHub.OnDisconnected(): pas de méthode appropriée trouvée pour remplacer
Je ne sais pas comment résoudre ce problème s'il vous plaît aidez-moicomment remplacer les méthodes SignalR en 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); 
     } 
    } 
} 

Répondre

0

pour SignalR 2.1.0+ , vous devez utiliser OnDisconected(bool stopCalled).

// 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);