Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.btn1.IsEnabled = false;

            //耗时长或有阻塞情况的不用线程池中的线程
            //ThreadPool.QueueUserWorkItem(fn => {
            //    Connect();
            //});
            try
            {
                Task task = Task.Factory.StartNew(() => {
                    var dic = new Dictionary <string, string>();
                    //dic.Add("sub-1", "/topic/latest_quotation_detail_CL1906");
                    //dic.Add("sub-2", "/topic/ask_bid_CL1906");
                    dic.Add("sub-1", "/topic/test");

                    WebSocketUtility ws = WebSocketUtility.Create("ws://market.future.alibaba.com/webSocket/zd/market", dic);
                    ws.Connect(onMessage);
                }, TaskCreationOptions.LongRunning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 初始化socket
        /// </summary>
        public void BindSocket()
        {
            Task task = Task.Factory.StartNew(() =>
            {
                var dic = new Dictionary <string, string>();
                dic.Add("sub-0", "/topic/latest_quotation_" + exchangeId + "." + productId + ".*");

                WebSocketUtility ws = WebSocketUtility.Create("ws://market.future.alibaba.com/webSocket/zd/market", dic);
                ws.Connect(delegate(string data)
                {
                });
            }, TaskCreationOptions.LongRunning);
        }