Exemple #1
0
        public static IAsyncResult BeginJoin(AvailableNetworkSession availableSession, AsyncCallback callback, Object asyncState)
        {
            if (Session != null || AsyncCreateCaller != null || AsyncFindCaller != null || AsyncJoinCaller != null)
            {
                throw new InvalidOperationException("Only one NetworkSession allowed");
            }
            if (availableSession == null)
            {
                throw new ArgumentNullException("availableSession");
            }

            AsyncJoinCaller = new AsyncJoin(InternalJoin);
            IAsyncResult result = null;

            try
            {
                result = AsyncJoinCaller.BeginInvoke(availableSession, callback, asyncState);
            }
            catch
            {
                AsyncJoinCaller = null;
                throw;
            }
            return(result);
        }
Exemple #2
0
        private async void BtnLogin_Click(object sender, EventArgs e)
        {
            string userName = this.txtUserName.Text.Trim();

            if (string.IsNullOrWhiteSpace(userName))
            {
                MessageBox.Show("请输入用户名!", "提示", MessageBoxButtons.OK);
                return;
            }

            AsyncJoin asyncJoin = new AsyncJoin(this.CeChatRoomService.Join);
            await Task.Factory.FromAsync(asyncJoin.BeginInvoke(userName, null, null), asyncJoin.EndInvoke);

            // 远程服务User对象赋值
            User user = service.GetService <User>();

            user.UserName = userName;

            this.Visible = false;

            // 展示新窗口
            service.GetRequiredService <FrmChatting>().Show();
        }