0
我有一個集線器需要從客戶端這樣的請求,調用:執行長輪詢數據庫在signalR樞紐
[HubName("Check")]
public class Check : Hub
{
private long _sessionId;
private string _sortType;
private int _tableCount;
private Timer _timer;
public void Car(long sessionId, string sortType, int tableCount)
{
_sessionId = sessionId;
_sortType = sortType;
_tableCount = tableCount;
StartCarTimer();
}
public void StartCarTimer()
{
_timer = new Timer(3000);
_timer.Elapsed += CarTimerElapsed;
_timer.Start();
}
void CarTimerElapsed(object sender, ElapsedEventArgs e)
{
int countCars = CountCars();
if (countCarPrices > _tableCount)
{
_tableCount = countCarPrices;
Clients.All.car(GetCarTable());
}
}
private int GetCars()
{
CarPrices carPrices = new CarPriceRepository().FindCarPricesById(_sessionId);
return carPrices;
}
}
我簡化它一點點,但基本上我是輪詢數據庫每隔3幾秒鐘檢查變化,這真的感覺像可怕的設計。我一直在尋找無處不在的解決方案。通過一個朋友建議
一種方法是通知signalR集線器從更新數據庫服務的服務器端,但我不知道該怎麼做。
有人請指點我正確的方向?至少2客戶端之間
你可以寫一個新的web服務在2個應用程序之間進行更新時進行通信 – Geezer68
您能解釋您要做什麼以及您有什麼問題? – thepirat000
這個問題在我想要做什麼以及我有什麼問題時很明顯。大聲笑... – Dimo