How can I cancel a hovering task?

We have a Windows service that calls a third-party method, which may hang if the end-user is configured incorrectly, which is difficult to verify in advance. We handle this risk by calling a method in a timeout task:

private int? FooWithTimeout()
{
    var timeout = TimeSpan.FromMinutes(1);
    var task = Task.Run(Foo);

    if (!task.Wait(timeout))
    {
        Log("Foo timed out...");
        return null;
    }

    if (task.IsFaulted)
    {
        Log("Foo threw an exception...");
        return null;
    }

    return task.Result;
}

A third-party method blocks the eternal wait for input from a resource that cannot respond. It supports not canceling support in any way, form or form, and also does not have a built-in timeout. Our concern is that as the service starts, these tasks will continue to block and slowly accumulate, eventually consuming a large amount of resources.

? - / ? , ?

: Crystal Reports. , , - (, Microsoft XPS Document Writer , , ). , , , , Windows, , , . , , , , .

+4
2

, , ,

. , , . , . . ( , ), , .

.NET . . .

AppDomains , . , , AppDomain . , . , -.

, - . . , , .

+3

, - - .

:

, , .NET?

:

WM_Close #?

, , ...: -)

0

All Articles