Esempio n. 1
0
 private void buttonStart_Click(object sender, System.EventArgs e)
 {
     _user                             = new LanUser();
     _user.NickName                    = textBoxNN.Text;
     _user.UserEntry                  += _user_UserEntry;
     _user.UserExit                   += _user_UserExit;
     _user.UserStateChange            += _user_UserStateChange;
     _user.Send                       += _user_Send;
     _user.TextMessageReceived        += _user_TextMessageReceived;
     _user.ImageReceived              += _user_ImageReceived;
     _user.FileTransportRequested     += _user_FileTransportRequested;
     _user.FileReceiveProgressChanged += _user_FileTransportProgressChanged;
     _user.FileSendProgressChanged    += _user_FileSendProgressChanged;
     _user.Listen();
     buttonStart.Enabled = false;
     buttonClose.Enabled = true;
 }
Esempio n. 2
0
        private void FormLanIM_Load(object sender, EventArgs e)
        {
            //此处需要注意,一定要把主线程UI传给LanUser,否则下面的线程调用主线程的部分会错,
            //因为基本都没有采用invoke方式(虽然invoke方式也可以对应这种情况)
            SynchronizationContext context = SynchronizationContext.Current;

            TaskFactory tf = new TaskFactory();

            tf.StartNew(() =>
            {
                InitMainUser(context);

                InitUserListBox(context, "");

                //开始监听
                _user.Listen();

                //1秒后发送上线通知
                Thread.Sleep(800);
                _user.Login();
            });
        }