コード例 #1
0
        private static void Init_Instance(string _MeetingID, string _UserID, string _UserName, bool InitToSync)
        {
            UserName  = _UserName;
            MeetingID = _MeetingID;
            _UserID   = Socket_FixEmailUserID.ToSocket(_UserID);
            UserID    = _UserID;
            ClearInstance();
            string str     = SocketTool.GetUrl();
            string url_Imp = SocketTool.GetUrl_Imp();

            if (_MeetingID.ToLower().StartsWith("i"))
            {
                str = url_Imp;
            }
            instance = new SocketClient(str + "/JoinSyncServer", _MeetingID, 100, _UserID, _UserName, InitToSync, 2, "12");
            if (ReaderEvent != null)
            {
                instance.AddEventManager(ReaderEvent);
            }
            instance.AddEventManager(OpenEventList);
            instance.AddCloseEventManager(CloseEventList);
            if (CS_0024_003C_003E9__CachedAnonymousMethodDelegate3 == null)
            {
                CS_0024_003C_003E9__CachedAnonymousMethodDelegate3 = new ThreadStart(_003CInit_Instance_003Eb__2);
            }
            thread = new Thread(CS_0024_003C_003E9__CachedAnonymousMethodDelegate3);
            thread.IsBackground = false;
            thread.Start();
            for (int i = 0; i < 10; i++)
            {
                if (instance != null && instance.GetIsConnected())
                {
                    return;
                }
                Thread.Sleep(10);
            }
            if (instance == null || !instance.GetIsConnected())
            {
                instance = null;
            }
        }
コード例 #2
0
        private static void Init_Instance(string _MeetingID, string _UserID, string _UserName, bool InitToSync)
        {
            UserName  = _UserName;
            MeetingID = _MeetingID;
            _UserID   = Socket_FixEmailUserID.ToSocket(_UserID);
            UserID    = _UserID;
            ClearInstance();
            //if (thread != null)
            //{
            //    thread.Abort();
            //}
            //if (instance != null)
            //{
            //    instance = null;
            //}

            // new SocketClient(syncServerUrl, meetingId, maxClient, clientId, clientName, isSync, clientType, func, true);
            // clientType 2是PC
            string SyncServerUrl     = SocketTool.GetUrl();
            string SyncServerUrl_Imp = SocketTool.GetUrl_Imp();

            if (_MeetingID.ToLower().StartsWith("i") == true)
            {
                SyncServerUrl = SyncServerUrl_Imp;
            }
            instance = new SocketClient(SyncServerUrl + "/JoinSyncServer", _MeetingID, 100, _UserID, _UserName, InitToSync, 2, "12");
            if (ReaderEvent != null)
            {
                instance.AddEventManager(ReaderEvent);
            }
            instance.AddEventManager(OpenEventList);
            instance.AddCloseEventManager(CloseEventList);


            thread = new Thread(delegate()
            {
                try
                {
                    //run()方法是無窮迴圈,所以要開Thread去跑
                    if (instance != null)
                    {
                        instance.run();
                    }
                }
                catch (Exception ex)
                {
                    LogTool.Debug(ex);
                }
            });
            thread.IsBackground = true;
            thread.Start();

            // 延遲一下,等待IEventManager.run 開始跑。
            //Thread.Sleep(100);

            int i = 0;

            while (i < 10)
            {
                if (instance != null && instance.GetIsConnected() == true)
                {
                    return;
                }

                Thread.Sleep(10);

                i++;
            }

            if (instance == null || instance.GetIsConnected() == false)
            {
                instance = null;
            }
        }