Winform Cefsharp:无法清除缓存目录

时间:2019-01-24 22:33:03

标签: c# winforms cefsharp

我在CefSharp项目中使用WinForm
我不会实时清除缓存目录:

if (browser != null)
{
    BrowserPanel.Controls.Remove(browser);
    browser = null;
}

String cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TelegramParser\Users\" + userName;
if (Directory.Exists(cachePath))
{
    Directory.Delete(cachePath, true);
}

但是我总是收到一个错误消息,那就是无法删除该目录。

这就是我声明浏览器的方式:

String cachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TelegramParser\Users\" + userName;

if (!System.IO.Directory.Exists(cachePath))
{
    System.IO.Directory.CreateDirectory(cachePath);
} 

var requestContextSettings = new RequestContextSettings { CachePath = cachePath };

if (browser != null && BrowserPanel.Controls.Contains(browser))
    BrowserPanel.Controls.Remove(browser);

browser = new ChromiumWebBrowser();
browser.RequestContext = new RequestContext(requestContextSettings, new CustomRequestContextHandler());
browser.Dock = DockStyle.Fill;

JsDialogHandler js1 = new JsDialogHandler();
browser.JsDialogHandler = js1;

BrowserPanel.Controls.Add(browser);
browser.Load("https://google.com/");

该如何解决?

0 个答案:

没有答案