开发者

SilverLight Socket Issue

开发者 https://www.devze.com 2023-03-11 15:33 出处:网络
I\'m trying write a silverlight application, socket can connect to 127.0.0.1:4505 but arg.completed event doesn\'t work

I'm trying write a silverlight application, socket can connect to 127.0.0.1:4505 but arg.completed event doesn't work

arg.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, 4505);
            arg.UserToken = sck;
            arg.Completed += new EventHandler<SocketAsyncEventArgs>(arg_Completed);
            sck.ConnectAsync(arg);

void arg_Completed(object sender, SocketAsyncEventArgs e)
        {
            label1.Content = "Durum!";
            if (e.LastOperation开发者_Python百科 == SocketAsyncOperation.Connect)
            {
                label1.Content = "Bağlandı!";
            }          
        }


Have you considered that ConnectAsync may not be completing asynchronously. Have a read of its documentation here.

You should be testing the returned boolean value from ConnectAsync, if its true then the completed event will fire, if not then the operation completed synchronously and ConnectAsync will not fire. The fact that you are using the local 127.0.0.01 increases the likelyhood for a synchronous completion.

On a synchronous connection the args object you passed into the call will have been mutated accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消