cancellation

Checking if a Java Timer is cancelled

时光总嘲笑我的痴心妄想 提交于 2019-12-01 03:15:33
Why is there no isCancelled method for a java.util.Timer object? I would like to schedule a task if the Timer has not been cancelled, and run it directly (on the same thread) if it has been cancelled. Is the only option to catch the IllegalStateException that might occur if the Timer already has been cancelled? (It feels wrong to catch an IllegalStateException ). Marko Topolnik How sure are you that you want to use Timer ? Use ExecutorService instead, which has isShutdown and has a slew of other benefits to boot. A general recommendation as of Java 5 has been to replace Timer s with

Stopping a task without a CancellationToken

£可爱£侵袭症+ 提交于 2019-12-01 02:59:52
问题 I am using an external library that has async methods, but not CancellationToken overloads. Now currently I am using an extension method from another StackOverflow question to add a CancellationToken : public async static Task HandleCancellation(this Task asyncTask, CancellationToken cancellationToken) { // Create another task that completes as soon as cancellation is requested. http://stackoverflow.com/a/18672893/1149773 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();

Pattern for long-running operation with cancellation ability

巧了我就是萌 提交于 2019-12-01 00:22:02
In order to perform long-running (let it be search in this context) operation, I put the loading logic inside a TPL task, so the general method Search() is called on background thread. Search() operation can be long enough, so I need the ability to cancel it properly, using the CancellationToken . But the Search() operation did not return until it finished, so I have to do some logic in order to implement convenient and (!) fast cancellation. Using WaitHandle's I can implement something like this: private void StartSearch() // UI thread { CancellationTokenSource s = new CancellationTokenSource

F# How Async<'T> cancellation works?

夙愿已清 提交于 2019-11-30 23:29:56
问题 I was pretty comfortable with how async cancellations where done in C# with the TPL, but I am a little bit confused in F#. Apparently by calling Async.CancelDefaultToken() is enough to cancel outgoing Async<'T> operations. But they are not cancelled as I expected, they just... vanishes... I cannot detect properly the cancellation and tear down the stack properly. For example, I have this code that depends on a C# library that uses TPL: type WebSocketListener with member x.AsyncAcceptWebSocket

Checking if a Java Timer is cancelled

半城伤御伤魂 提交于 2019-11-30 22:39:52
问题 Why is there no isCancelled method for a java.util.Timer object? I would like to schedule a task if the Timer has not been cancelled, and run it directly (on the same thread) if it has been cancelled. Is the only option to catch the IllegalStateException that might occur if the Timer already has been cancelled? (It feels wrong to catch an IllegalStateException ). 回答1: How sure are you that you want to use Timer ? Use ExecutorService instead, which has isShutdown and has a slew of other

Pattern for long-running operation with cancellation ability

岁酱吖の 提交于 2019-11-30 19:32:50
问题 In order to perform long-running (let it be search in this context) operation, I put the loading logic inside a TPL task, so the general method Search() is called on background thread. Search() operation can be long enough, so I need the ability to cancel it properly, using the CancellationToken . But the Search() operation did not return until it finished, so I have to do some logic in order to implement convenient and (!) fast cancellation. Using WaitHandle's I can implement something like

How to correctly clean up after long running task is cancelled

南笙酒味 提交于 2019-11-30 14:29:09
I've created a class whose purpose is to abstract away the control of concurrent access to a queue. The class is designed to be instantiated on a single thread, written to by multiple threads and then read from a subsequent single thread. I have a single long running task generated inside the class which will perform a blocking loop and fire an event if an item is successfully dequeued. My question is this: Is my implementation of the cancelling of the long running task AND subsequent clean up/reset correct usage of the CancellationTokenSource object? Ideally, I'd like an active object to be

Using Android's build-in acoustic echo cancellation

£可爱£侵袭症+ 提交于 2019-11-30 13:59:31
Does anyone know how to use Android device's built-in acoustic echo cancellation? It is located somewhere in silicon and is used for GSM/CDMA speakerphone calls. We'd really like to tap into it for a VoIP application instead of rolling our own. Ben I was finally able to get echo cancellation to work on my Arm5 (WM8650) processor (Android 2.2). Below are the steps I took. I wrapped Speex with JNI and called echo processing routines before sending PCM frames to encoder. No echo was canceled no matter what Speex settings I tried. Because Speex is very sensitive to delay between playback and echo

HttpRequest not aborted (cancelled) on browser abort in ASP.NET Core MVC

断了今生、忘了曾经 提交于 2019-11-30 08:41:20
I wrote the following MVC Controller to test cancellation functionality: class MyController : Controller { [HttpGet("api/CancelTest")] async Task<IActionResult> Get() { await Task.Delay(1000); CancellationToken token = HttpContext.RequestAborted; bool cancelled = token.IsCancellationRequested; logger.LogDebug(cancelled.ToString()); return Ok(); } } Say, I want to cancel the request, so the value ' true ' is logged in the controller action above. This is possible server-side if the server implements the IHttpRequestLifetimeFeature. Luckily Kestrel does, and this can be accomplished the

How to correctly clean up after long running task is cancelled

北城以北 提交于 2019-11-29 21:17:56
问题 I've created a class whose purpose is to abstract away the control of concurrent access to a queue. The class is designed to be instantiated on a single thread, written to by multiple threads and then read from a subsequent single thread. I have a single long running task generated inside the class which will perform a blocking loop and fire an event if an item is successfully dequeued. My question is this: Is my implementation of the cancelling of the long running task AND subsequent clean