C# CEFSharp应用程序显示空白屏幕,然后对此作出响应';一分钟后他就要走了
我一直在开发一个应用程序,它使用CEFSharp(版本83.4.20)加载我公司的VOIP平台(engage.ringcentral.com)。源在Github上 该应用程序已经运行了大约一个月,在投入生产后,我收到了一个奇怪问题的报告。人们看到的是一个空白屏幕,无法与网页交互( )。几分钟后,问题似乎自行解决,他们可以再次与网页互动。我自己还没能重现这个问题 我认为这可能是一个渲染问题。到目前为止,我已尝试在我的应用程序中调整以下内容: 删除下面的行C# CEFSharp应用程序显示空白屏幕,然后对此作出响应';一分钟后他就要走了,c#,windows,winforms,cefsharp,ringcentral,C#,Windows,Winforms,Cefsharp,Ringcentral,我一直在开发一个应用程序,它使用CEFSharp(版本83.4.20)加载我公司的VOIP平台(engage.ringcentral.com)。源在Github上 该应用程序已经运行了大约一个月,在投入生产后,我收到了一个奇怪问题的报告。人们看到的是一个空白屏幕,无法与网页交互( )。几分钟后,问题似乎自行解决,他们可以再次与网页互动。我自己还没能重现这个问题 我认为这可能是一个渲染问题。到目前为止,我已尝试在我的应用程序中调整以下内容: 删除下面的行 settings.CefCommandLi
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-gpu-shader-disk-cache", "1");
替换为
settings.CefCommandLineArgs.Add("disable-gpu-compositing");
不幸的是,这并没有解决问题,我不确定我缺少了什么
CEF初始化的相关代码位于InitializeChromium方法下的中。见下文
//
// Chrome
//
private CefSharp.WinForms.ChromiumWebBrowser chromeBrowser;
public ChromiumWebBrowser InitializeChromium(string URL, string Name)
{
// Check if already Initialized
if (Cef.IsInitialized == false)
{
CefSettings settings = new CefSettings();
// Enable Logging if debugging or console window
if (!this.debug || !this.console)
{
settings.LogSeverity = LogSeverity.Disable;
}
else
{
settings.LogSeverity = LogSeverity.Verbose;
}
// Enable Microphone settings
settings.CefCommandLineArgs.Add("enable-media-stream", "1");
// Set Custom Browser Paths
settings.CefCommandLineArgs.Add("disable-gpu-shader-disk-cache", "1");
// Disable GPU to fix rendering issues on some machines.
settings.CefCommandLineArgs.Add("disable-gpu");
// Disable CORS protection (cross site scripting) which the engage.ringcentral.com site doesn't seem to like/respect, disabled as the website doesn't seem to improve with this turned on.
//settings.CefCommandLineArgs.Add("disable-web-security");
// Enable session Cookie persistence, disabled as it's unneeded.
//settings.PersistSessionCookies = true;
// Custom Browser paths
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\CefSharp.BrowserSubprocess.exe");
settings.LocalesDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\locales\");
settings.ResourcesDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\");
// Check if Resources folder is writable. If it isn't then write to application data.
DirectoryInfo di = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\"));
if ((di.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
settings.RootCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"EngageRC\CEFSharp\cache");
settings.CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"EngageRC\CEFSharp\cache");
settings.LogFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"EngageRC\CEFSharp\debug.log");
}
else
{
settings.RootCachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\cache");
settings.CachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\cache");
settings.LogFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\CEFSharp\debug.log");
}
// Initialize cef with the provided settings or add new tab
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
}
// Create a browser component
chromeBrowser = new ChromiumWebBrowser(URL);
// Set Name
chromeBrowser.Name = Name;
// Adjust size and scaling
this.chromeBrowser.Dock = DockStyle.Fill;
this.chromeBrowser.Width = this.Width;
this.chromeBrowser.Height = this.Height;
// Add control
this.Controls.Add(chromeBrowser);
// Bring to front
this.chromeBrowser.BringToFront();
// Set label to Goodbye.
this.label1.Text = "Goodbye";
// Return control
return chromeBrowser;
}
我无法用我的Google foo找到任何以前的问题,所以这似乎不是其他人看到的应用程序。我还在学习C#的诀窍,所以这100%可能是我自己的错,我做错了什么
我能够从一台遇到该问题的机器上获得详细的日志记录。我主要看到以下错误。完整日志在
[0729/083616.491:错误:paint_controller.cc(646)]PaintController::FinishCycle()已完成
任何有助于解决此问题的想法或建议都将不胜感激
更新:根据@amaitland的有用评论,似乎这种行为可能是由使用线程引起的。在我不应该使用的线程上睡眠 在检查了我的代码之后,看起来我在两个地方都有这个 首先,我调用thread.sleep以等待浏览器的缩放级别与我保存到windows isolatedstorage的值匹配。除非应用程序第一次启动,否则不应运行此操作。我不认为这是个问题,但为了安全起见,我把它贴在这里。() 根据我所听到的,我应该让通知表单在与主应用程序不同的线程上运行,然后呢?还是我离基地太远了
更新: 我能够将通知移动到它自己的线程中。我将关闭这个问题,并将有用户的测试,看看是否空白屏幕仍然存在。
再次感谢你的帮助 @amaitland的评论有助于缩小此问题的范围。考虑在链接中添加相关代码。链接在将来可能会变得无效。已更新,感谢您的提示!你用的是什么版本?你检查日志文件了吗?建议始终启用日志记录。CEFSharp版本83.4.20。不幸的是,我已经为报告问题的用户禁用了日志记录,所以我还没有机会查看这些日志。我试图让他们在启用日志记录的情况下重现这个问题,但这是一种零星的行为。这种行为通常是由于错误地阻塞/休眠了一个不应该执行的线程而导致的。
public void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args)
{
ChromiumWebBrowser chrome = (ChromiumWebBrowser)sender;
if (!args.IsLoading) // Loading finished.
{
// If first load set zoom level to previous level
if (firstLoad < 3)
{
try
{
double zoom = double.Parse(ConfigReader.ReadIsolatedStorage("z"), System.Globalization.CultureInfo.InvariantCulture);
while (args.Browser.GetZoomLevelAsync().Result != zoom) { chrome.SetZoomLevel(zoom); Thread.Sleep(50); }
}
catch { }
firstLoad++;
}
// These JS and CSS modifications built into EngageRC
string hotfixJS = "";
string hotfixCSS = "/* Fix for dropdowns */ ul.dropdown-menu[style=\\\"opacity: 1;\\\"] {display: block !important; } /* End fix for dropdowns */";
// Inject custom javascript and css code on page load
chrome.ExecuteScriptAsync(hotfixJS);
chrome.ExecuteScriptAsync("var engageRCSS = document.getElementById('EngageRCSS'); if (!engageRCSS) { var node = document.createElement('style'); node.setAttribute('id', 'EngageRCSS'); node.innerHTML = \"" + hotfixCSS +"\"; document.body.appendChild(node); }");
if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Custom.js"))) { chrome.ExecuteScriptAsync(System.IO.File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Custom.js"))); }
if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Custom.css"))) { chrome.ExecuteScriptAsync("var customCSS = document.getElementById('customcss'); if (!customCSS) { var node = document.createElement('style'); node.setAttribute('id', 'customcss'); node.innerHTML = \"" + System.IO.File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Custom.css")).Replace("\n", String.Empty).Replace("\r", String.Empty).Replace("\t", String.Empty).Replace("\"", "\\\"") + "\"; document.body.appendChild(node); }"); }
}
}
public void displayNotification(string Title = "EngageRC", string Message = "")
{
// Display notification for 5 seconds
Notify notification = MainWindow.notification;
try
{
if (!IsActive(hWnd)) // Check if application is already active.
{
string config = ConfigReader.GetConfigValue("NotificationsDisabled").ToLower();
if (!(config == "true" || config == "1"))
{
notification.NewNotification(Title, Message, 5000);
}
config = ConfigReader.GetConfigValue("GetFocusOnCallDisabled").ToLower();
if (!(config == "true" || config == "1") && (Message == "You have incoming call"))
{
// Minimize window
ShowWindow(hWnd, 0x02);
// Restore window to previous state.
ShowWindow(hWnd, 0x09);
}
config = ConfigReader.GetConfigValue("GetFocusOnPendingDispositionDisabled").ToLower();
if (!(config == "true" || config == "1") && (Message == "You have a disposition pending"))
{
// Minimize window
ShowWindow(hWnd, 0x02);
// Restore window to previous state.
ShowWindow(hWnd, 0x09);
}
}
}
catch { notification.SetIconVisible(false); }
finally
{
Thread.Sleep(4999);
notification.SetIconVisible(false);
}
}