예제 #1
0
        static void PushData()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var hub = GlobalHost.ConnectionManager.GetHubContext <HubHelper>();

                while (IsRun)
                {
                    Thread.Sleep(1000);
                    long finalBlockNumber;
                    var info = ChainDataService.GetGUCAutodataInfo(out finalBlockNumber);
                    if (info.GetHashCode() == 0 || finalBlockNumber == 0)
                    {
                        continue;
                    }
                    var clients = HubHelper.connections.Where(x => x.Value.LastFinalBlockNumber != finalBlockNumber).Select(x => x.Key).ToList();
                    if (clients.Any() == false)
                    {
                        continue;
                    }
                    hub.Clients.Clients(clients).getMessage(info);
                    foreach (var item in HubHelper.connections)
                    {
                        if (clients.Contains(item.Key))
                        {
                            item.Value.LastFinalBlockNumber = finalBlockNumber;
                        }
                    }
                    Console.Out.Flush();
                }
            });
        }
예제 #2
0
 private static void PushData()
 {
     var task = Task.Factory.StartNew(() => {
         while (IsRun)
         {
             Thread.Sleep(1000);
             //todo: wait api
             var data     = ChainDataService.GetBlockByID(100);
             var sessions = wsServer.GetAllSessions();
             sessions.AsParallel().ForAll(x => {
                 x.Send();
             });
         }
     });
 }