private void DeleteCookies() { var callback = new TaskDeleteCookiesCallback(); callback.Task.ContinueWith(task => { if (!task.IsCompleted || task.Result == TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted) { logger.Warn("Failed to delete cookies!"); } else { logger.Debug($"Deleted {task.Result} cookies."); } }); if (Cef.GetGlobalCookieManager().DeleteCookies(callback: callback)) { logger.Debug("Successfully initiated cookie deletion."); } else { logger.Warn("Failed to initiate cookie deletion!"); } }
public async Task TaskDeleteCookiesCallbackDispose() { var callback = new TaskDeleteCookiesCallback(); //Execute Dispose on seperate Thread as in practice will be called on the CEF IO Thread. Task.Delay(100).ContinueWith(x => { var c = (IDeleteCookiesCallback)callback; //Dispose of the callback, no cookies were deleted //This is a realworld example of how CEF interacts with the callback c.Dispose(); }, TaskScheduler.Default); var result = await callback.Task; Assert.Equal(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted, result); }
public async Task TaskDeleteCookiesCallbackOnComplete() { const int numberOfCookiesDeleted = 10; var callback = new TaskDeleteCookiesCallback(); //Execute OnComplete on seperate Thread as in practice will be called on the CEF IO Thread. Task.Delay(100).ContinueWith(x => { var c = (IDeleteCookiesCallback)callback; c.OnComplete(numberOfCookiesDeleted); c.Dispose(); }, TaskScheduler.Default); var result = await callback.Task; Assert.Equal(numberOfCookiesDeleted, result); }