Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Why does NSPasteboard run so slowly in TcpListener's async task?

$
0
0

I have a app(webview + xamarin) which support websocket server.
But when I use chrome to debug js, the server side is so slow. I simplify the code as follows:

            Task.Run(async () =>
            {
                var tcpListener = new TcpListener(IPAddress.Any, 50505);
                tcpListener.Start();
                while (true)
                {
                    var tcpClient = await tcpListener.AcceptTcpClientAsync();
                    NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                    {
                        var sw = new Stopwatch();
                        sw.Start();
                        var text = NSPasteboard.GeneralPasteboard.GetStringForType(NSPasteboard.NSStringType);
                        sw.Stop();
                        Console.WriteLine("ElapsedMs: " + sw.ElapsedMilliseconds);
                    });
                }
            }).ConfigureAwait(false);

Then I create a test html file contains websocket client js code.

  1. From terminal, run TcpListenerTest app.
  2. Open chrome, maximum it( let TcpListenerTest app to background).
  3. In chrome, open a web page, and copy some words(abount 100 words).
  4. Wait about 5 minutes.
  5. In chrome, open the test html file.
  6. Wait about 10 seconds and turn to terminal to see the output.

In most case, ElapsedMs is about 10,000( 10 seconds).

Only the first time after restart computer, it will occur.


Viewing all articles
Browse latest Browse all 204402

Trending Articles