이것은 내가 발견 한 코드입니다. 기다리고 키워드 나는 중요한 조각 실종된다`VisitAllCookiesAsync` 방법 내장과
class CookieCollector : ICookieVisitor
{
private readonly TaskCompletionSource<List<Cookie>> _source = new TaskCompletionSource<List<Cookie>>();
public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
{
_cookies.Add(cookie);
if (count == (total - 1))
{
_source.SetResult(_cookies);
}
}
// https://github.com/amaitland/CefSharp.MinimalExample/blob/ce6e579ad77dc92be94c0129b4a101f85e2fd75b/CefSharp.MinimalExample.WinForms/ListCookieVisitor.cs
// CefSharp.MinimalExample.WinForms ListCookieVisitor
public Task<List<Cookie>> Task => _source.Task;
public static string GetCookieHeader(List<Cookie> cookies)
{
StringBuilder cookieString = new StringBuilder();
string delimiter = string.Empty;
foreach (var cookie in cookies)
{
cookieString.Append(delimiter);
cookieString.Append(cookie.Name);
cookieString.Append('=');
cookieString.Append(cookie.Value);
delimiter = "; ";
}
return cookieString.ToString();
}
private readonly List<Cookie> _cookies = new List<Cookie>();
public void Dispose()
{
}
}
// usage:
void foo()
{
var cookieManager = Cef.GetGlobalCookieManager();
var visitor = new CookieCollector();
cookieManager.VisitUrlCookies(targetUrl, true, visitor);
var cookies = await visitor.Task; // AWAIT !!!!!!!!!
var cookieHeader = CookieCollector.GetCookieHeader(cookies);
}
발생한 된 문제? https://github.com/cefsharp/CefSharp/blob/11dee93bf331f012dd6416fb2f2162549d9137a3/CefSharp/ICookieManager.cs#L54 – amaitland