2016-05-02 2 views
-1

Я работаю над проектом asp.net mvc5, и я хочу создать чат с сигналом. Итак, я получил Microsoft.Aspnet.SignalR от nuget, и я использовал класс SignalR Hub для концентратора и теперь я не хочу, чтобы переопределить метод OnDisconnected() .Но я получаю ошибку «ChatHub.OnDisconnected()»: нет подходящего метода найденную переопределить
я не знаю, как решить эту проблему, пожалуйста, помогите мнеКак переопределить методы SignalR в 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); 
     } 
    } 
} 

ответ

0

для SignalR 2.1.0+ , вам необходимо использовать 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);