Files
cefsharp/CefSharp/Internals/FramePendingTaskRepository.cs
campersau 331ee6a305 Core - Cancel pending tasks when browser crashed or v8 context gets released (#5145)
* Core - Cancel pending tasks when browser crashed or v8 context gets released

* Use TrySetCanceled to cancel pending tasks

* Adjust test to use chrome://crash for simulating a crash

* Add tests for javascript callbacks

* Rename tests and add tests for calling Execute multiple times

* Move FramePendingTaskRepository to its own file

* Rename test to ShouldCancelAfterV8ContextChange

* Fix compile error on .NET Framework

* adjust ShouldTimeoutIfNavigationOccurs test which now throws a TaskCanceledException on navigation
2025-08-22 12:14:38 +10:00

34 lines
1.1 KiB
C#

// Copyright © 2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace CefSharp.Internals
{
internal sealed class FramePendingTaskRepository<TResult> : IDisposable
{
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> PendingTasks { get; } =
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> CallbackPendingTasks { get; } =
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
public void Dispose()
{
foreach (var tcs in PendingTasks.Values)
{
tcs.TrySetCanceled();
}
PendingTasks.Clear();
foreach (var tcs in CallbackPendingTasks.Values)
{
tcs.TrySetCanceled();
}
CallbackPendingTasks.Clear();
}
}
}