void DispatchMessages()
 {
     try
     {
         while (isRunning)
         {
             if (eventHandle.WaitOne(-1, false) && isRunning)
             {
                 var count = messages.Count;
                 while (count > 0)
                 {
                     count--;
                     if (messages.TryDequeue(out IMessage message))
                     {
                         _manager.Send(message);
                     }
                 }
             }
         }
     }
     catch (SocketException)
     {
         System.Diagnostics.Debug.WriteLine("Client Closed");
         // socket closed
     }
     catch (System.IO.IOException)
     {
         System.Diagnostics.Debug.WriteLine("Unable to send data");
         // invalid write
     }
 }
Exemple #2
0
        public async Task <bool> Start()
        {
            _hook.Init();
            ScreenConfiguration configuration = new ScreenConfiguration();
            //there is some kind of dpi awareness bug here on windows. not sure exactly what's up.
            var displays = _hook.GetDisplays();
            var count    = displays.Count;
            var display  = displays[0];
            var s        = configuration.AddScreen(display, display.GetDpi(), state.ClientName);

            for (int i = 1; i < count; i++)
            {
                display = displays[i];
                s       = configuration.AddScreenRight(s, display, display.GetDpi(), state.ClientName);
            }
            _connection.Start();
#if QUEUE_CLIENT
            _dispatcher.StartDispatcher();
#endif
            var localScreens = configuration.AllScreen;
            await _connection.Send(new CheckInMessage(state.ClientName, localScreens).GetBytes());

            var checkIn = await _connection.WaitForCheckIn();

            // server screens
            var screens = checkIn.Screens;
            ScreenConfiguration screenConfiguration = _screen.ScreenConfiguration;
            screenConfiguration.AddScreens(screens);
            screenConfiguration.AddScreensRight(localScreens);
            // Focus Current Client
            state.CurrentClientFocused = true;
            _hook.Hook.SetMousePos(state.LastPositionX, state.LastPositionY);

            _hook.Start();

            return(true);
        }