Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering in console app not working if console app is starting as windows service child process #3177

Open
MJeli opened this issue Feb 1, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@MJeli
Copy link

MJeli commented Feb 1, 2023

Description
Rendering in console apps works if I start the console app in the context of the current logged in user.
If i start the console app as child process of a Windows service (no UI available) CreateCoreWebView2ControllerAsync does not return.

internal class Program
    {
        private static readonly IntPtr HWND_MESSAGE = new IntPtr(-3);

        [STAThread]
        static void Main(string[] args)
        {
            Test();
            Application.Run();
        }

        static async void Test()
        {
            SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
            await Task.Delay(1); // wait for the application loop to start
            var browserEnv = await CoreWebView2Environment.CreateAsync();
            var wvController = await browserEnv.CreateCoreWebView2ControllerAsync(HWND_MESSAGE); // not working in a Windows Service Childprocess
            wvController.Bounds = new System.Drawing.Rectangle(0, 0, 100, 100);
            wvController.CoreWebView2.Navigate("http://localhost/");
            TaskCompletionSource<bool> tsc = new TaskCompletionSource<bool>();
            wvController.CoreWebView2.NavigationCompleted += (s, e) =>
            {
                tsc.SetResult(true);
            };
            await tsc.Task;
            using (FileStream stream = new FileStream("D:\\testImg.png", FileMode.Create))
            {
                await wvController.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, stream);
            }
            Application.Exit();
        }
    }

Version
SDK: 1.0.1518.46
Runtime: Evergreen 109.0.1518.70
OS: Win11 22H2
Framework: .NET 4.8 Console App

@MJeli MJeli added the bug Something isn't working label Feb 1, 2023
@victorhuangwq
Copy link
Collaborator

Hi, are you still facing this issue?

@MJeli
Copy link
Author

MJeli commented Dec 4, 2023

yes

@LiangTheDev
Copy link
Member

If it runs as SYSTEM account, it should be #1907, otherwise, it is likely #3458.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants