Esempio n. 1
0
        // Public methods
        ///////////////////////

        public static void Start(Action initialize)
        {
            if (thread != null)
            {
                return;
            }
            isRunning = true;
            thread    = Thread.Run("main loop", () => {
                initialize();
                MainLoop();
            });
            thread.Join();
            thread = null;
        }
Esempio n. 2
0
        // Public methods
        ///////////////////////

        public static void Start()
        {
            if (thread != null)
            {
                return;
            }
            thread = Thread.Run("event loop", () => {
                var moduleHandle       = GetModuleHandle(IntPtr.Zero);
                wndProcDelegate        = OnWndProc;
                var wndClass           = WndClassEx.New();
                wndClass.lpszClassName = CLASS_NAME;
                wndClass.lpfnWndProc   = wndProcDelegate;
                wndClass.hInstance     = moduleHandle;
                var classAtom          = RegisterClassExW(ref wndClass);
                if (classAtom == IntPtr.Zero)
                {
                    var lastError = Marshal.GetLastWin32Error();
                    Log.Error($"Could not register window class (code {lastError})");
                    return;
                }
                handle = CreateWindowExW(
                    0,
                    classAtom,
                    String.Empty,
                    0,
                    0,
                    0,
                    0,
                    0,
                    HWND_MESSAGE,
                    IntPtr.Zero,
                    moduleHandle,
                    IntPtr.Zero
                    );
                if (handle == IntPtr.Zero)
                {
                    var lastError = Marshal.GetLastWin32Error();
                    Log.Error($"Could create window with class {classAtom} (code {lastError})");
                    return;
                }
                System.Windows.Forms.Application.Run();
            });
        }