diff --git a/src/Infrastructure/AppWindow.cs b/src/Infrastructure/AppWindow.cs index a0671325..548145d7 100644 --- a/src/Infrastructure/AppWindow.cs +++ b/src/Infrastructure/AppWindow.cs @@ -12,7 +12,6 @@ using Sqlbi.Bravo.Infrastructure.Windows.Interop; using Sqlbi.Bravo.Models; using System; - using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -117,8 +116,6 @@ ThemeType GetTheme() private void OnWindowCreating(object? sender, EventArgs e) { - Trace.WriteLine($"::Bravo:INF:OnWindowCreating:{ _window.Title }"); - var theme = UserPreferences.Current.Theme; if (theme != ThemeType.Auto) { @@ -129,7 +126,6 @@ private void OnWindowCreating(object? sender, EventArgs e) private void OnWindowCreated(object? sender, EventArgs e) { - Trace.WriteLine($"::Bravo:INF:OnWindowCreated:{ _window.Title } ( { string.Join(", ", _host.GetListeningAddresses().Select((a) => a.ToString())) } )"); #if !DEBUG HandleHotKeys(register: true); #endif @@ -228,6 +224,12 @@ private void CheckForUpdate() } else if (updateInfo.IsUpdateAvailable) { + // HACK: see issue https://github.com/tryphotino/photino.NET/issues/87 + // Wait a bit in order to ensure that the PhotinoWindow message loop is started + // This is to prevent the .NET Runtime corecrl.dll fault with a win32 access violation + Thread.Sleep(5_000); + // HACK END << + var updateMessage = ApplicationUpdateAvailableWebMessage.CreateFrom(updateInfo); _window.SendWebMessage(updateMessage.AsString); @@ -243,15 +245,17 @@ private void CheckForUpdate() /// public void WaitForClose() { + // HACK: see issue https://github.com/tryphotino/photino.NET/issues/87 + // Wait a bit in order to ensure that the PhotinoWindow message loop is started + // This is to prevent the .NET Runtime corecrl.dll fault with a win32 access violation + // This should be moved to the OnWindowCreated handler after the issue has been resolved if (!_startupSettings.IsEmpty) { - // HACK: see issue https://github.com/tryphotino/photino.NET/issues/87 - // This should be moved to the OnWindowCreated handler after the issue has been resolved _ = Task.Factory.StartNew(() => { try { - Thread.Sleep(2000); + Thread.Sleep(2_000); var startupMessage = AppInstanceStartupMessage.CreateFrom(_startupSettings); var webMessageString = startupMessage.ToWebMessageString(); @@ -264,6 +268,7 @@ public void WaitForClose() } }); } + // HACK END << _window.WaitForClose(); } diff --git a/src/Infrastructure/Windows/WindowSubclass.cs b/src/Infrastructure/Windows/WindowSubclass.cs index dce8967b..978999f5 100644 --- a/src/Infrastructure/Windows/WindowSubclass.cs +++ b/src/Infrastructure/Windows/WindowSubclass.cs @@ -9,19 +9,11 @@ /// internal abstract class WindowSubclass : CriticalFinalizerObject, IDisposable { - //private static readonly int DetachUnsubclassMessage; - private readonly Comctl32.SUBCLASSPROC _subclassProc; private readonly IntPtr _subclassId; private readonly IntPtr _hWnd; - private object _lockSync = new(); + private readonly object _lockSync = new(); private bool _subclassInstalled; - //private bool _disposed; - - //static WindowSubclass() - //{ - // DetachUnsubclassMessage = User32.RegisterWindowMessageW("bravo_DetachSubclass"); - //} public WindowSubclass(IntPtr hWnd) { @@ -40,7 +32,7 @@ private IntPtr SubclassProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam } finally { - if (uMsg == (uint)WindowMessage.WM_NCDESTROY /* || uMsg == DetachUnsubclassMessage */) + if (uMsg == (uint)WindowMessage.WM_NCDESTROY) { DetachSubclass(); }