SignalR何时知道获得新值?

时间:2018-08-31 18:53:39

标签: c# asp.net signalr

我正在尝试创建一个带有gridview的网页,每当在其他程序中发生更新时,它将触发集线器并使用signalR使用新数据更新网格。

建立并从程序调用集线器,将值设置为true。我想读取该值,然后刷新网页,然后将该值设置回false。

这是我的JavaScript代码:

 var seiHub = $.connection.sEIDataTickerHub;

         function init() {
             var test = seiHub.invoke("RefreshPage").done(function () { });
             $('#txtDate').val(Boolean(test));
             if (Boolean(test)) {
                 $('#Btn_PageRefresh').click();
                 seiHub.invoke("UpdateSEIData", false).done(function () { });
             }
         }

         $.connection.hub.start().done(init);

这是Sei数据行情枢纽代码:

public class SEIDataTickerHub : Hub
{
    static readonly ILog log = LogManager.GetLogger(typeof(SEI));
    private readonly SEIDataTicker _seiDataTicker;
    public SEIDataTickerHub() : this(SEIDataTicker.Instance) { }

    public SEIDataTickerHub(SEIDataTicker seiDataTicker) {
        _seiDataTicker = seiDataTicker;
    }
    [HubMethodName("RefreshPage")]
    public bool GetUpdate() {
        log.Info(_seiDataTicker.GetUpdate());
        return _seiDataTicker.GetUpdate();
    }
    [HubMethodName("UpdateSEIData")]
    public void UpdateSEIData(bool update) {
        log.Info("Got Data From ZMill Application");
        _seiDataTicker.UpdateSeiData(update);
    }
}

Sei数据代码:

private readonly static Lazy<SEIDataTicker> _instance = new Lazy<SEIDataTicker>(() => new SEIDataTicker(GlobalHost.ConnectionManager.GetHubContext<SEIDataTickerHub>().Clients));
    private bool updater;
    private SEIDataTicker(IHubConnectionContext<dynamic> clients) {
        Clients = clients;
        //_SEI.Clear();
    }

    public void UpdateSeiData(bool update) {
        log.Info(update);
        updater = update;
    }
    public  bool GetUpdate() {
        log.Info("Getting value");
        return updater;
    }

    public static SEIDataTicker Instance {
        get {
            return _instance.Value;
        }
    }

    private IHubConnectionContext<dynamic> Clients { get; set; }

    public void BroadcastCurrentSEIData() {
        Clients.All.GetUpdate();
        UpdateSeiData(false);
    }

0 个答案:

没有答案