cancellation

Server based SwingWorker does not Stop

巧了我就是萌 提交于 2019-11-29 12:30:24
I have a boolean variable to control the execution of the server (start/stop) : private boolean ecoute=true; here is my class: sw=new SwingWorker<String,Void> (){ protected String doInBackground() throws Exception { try { server = new ServerSocket(Integer.parseInt(port.getText())); String str1="waiting for connexion.."; String str2="Connexion ok"; log.append(str1+"\n"); PrintWriter out=null; BufferedReader in=null; Socket socClient=null; while(ecoute){ socClient = server.accept(); log.append(str2+"\n"); in = new BufferedReader( new InputStreamReader(socClient.getInputStream()) ); out = new

Stopping a Thread, ManualResetEvent, volatile boolean or cancellationToken

我是研究僧i 提交于 2019-11-29 08:06:04
I have a Thread (STAThread) in a Windows Service, which performs a big amount of work. When the windows service is restarted I want to stop this thread gracefully. I know of a couple of ways A volatile boolean ManualResetEvent CancellationToken As far as I have found out Thread.Abort is a no go... What is the best practice ? The work is perfomed in another class than the one where the thread is started, so it is necessary to either introduce a cancellationToken parameter in a constructor or for example have a volatile variable. But I just can't figure out what is smartest. Update Just to

Implementing extension method WebRequest.GetResponseAsync with support for CancellationToken

*爱你&永不变心* 提交于 2019-11-29 00:09:46
The idea here is simple, but the implementation has some interesting nuances. This is the signature of the extension method I would like to implement in .NET 4 . public static Task<WebResponse> GetResponseAsync(this WebRequest request, CancellationToken token); Here is my initial implementation. From what I've read, the web request might need to be cancelled due to a timeout . In addition to the support described on that page, I want to properly call request.Abort() if cancellation is requested via the CancellationToken . public static Task<WebResponse> GetResponseAsync(this WebRequest request

Aborting a long running task in TPL

泄露秘密 提交于 2019-11-28 21:23:39
Our application uses the TPL to serialize (potentially) long running units of work. The creation of work (tasks) is user-driven and may be cancelled at any time. In order to have a responsive user interface, if the current piece of work is no longer required we would like to abandon what we were doing, and immediately start a different task. Tasks are queued up something like this: private Task workQueue; private void DoWorkAsync (Action<WorkCompletedEventArgs> callback, CancellationToken token) { if (workQueue == null) { workQueue = Task.Factory.StartWork (() => DoWork(callback, token), token

Is there a way to short circuit async/await flow?

萝らか妹 提交于 2019-11-28 19:46:31
问题 async function update() { var urls = await getCdnUrls(); var metadata = await fetchMetaData(urls); var content = await fetchContent(metadata); await render(content); return; } //All the four functions return a promise. (getCdnUrls, fetchMetaData, fetchContent, render) What if we want to abort the sequence from outside, at any time ? Say, when fetchMetaData is being executed, we realize the component is no longer needed to be rendered and we want to cancel the remaining operations

Cancel NetworkStream.ReadAsync using TcpListener

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 11:36:26
Consider the following simplified example (ready to roll in LinqPad, elevated account required): void Main() { Go(); Thread.Sleep(100000); } async void Go() { TcpListener listener = new TcpListener(IPAddress.Any, 6666); try { cts.Token.Register(() => Console.WriteLine("Token was canceled")); listener.Start(); using(TcpClient client = await listener.AcceptTcpClientAsync() .ConfigureAwait(false)) using(var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5))) { var stream=client.GetStream(); var buffer=new byte[64]; try { var amtRead = await stream.ReadAsync(buffer, 0, buffer.Length, cts

Android Speex echo cancellation problems

不羁的心 提交于 2019-11-28 05:35:44
问题 I have a basic audiorecord-audiotrack, udp packets voice chat between two android devices. It works, but I have a bad echo. I'm trying to remove the echo using Speex ported to android by JNI. The speex I imported works, but the echo cancellation doesn't. Native C code is: #include <jni.h> #include <speex/speex_echo.h> #define FRAME_SIZE 256 #define FILTER_LENGTH 800 SpeexEchoState *echoState; // Initialization of echo cancelation void Java_telefonie_voip_VoIPActivity_InitEcho(JNIEnv * env,

Getting the saved instruction pointer address from a signal handler

蓝咒 提交于 2019-11-28 05:32:55
My question is somewhat different from others that have asked about fault addresses. I'm trying to implement a horrible hack to determine, from a signal handler, whether the signal interrupted a syscall or ordinary user code by inspecting the code at the saved instruction pointer and comparing it against the possible syscall entry instructions for the host architecture it's running on. This is part of implementing correct POSIX thread cancellation that does not suffer from the race condition and resource leak described in my old question: How are POSIX cancellation points supposed to behave?

Getting the latest data from a promise returning service called repeatedly

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:11:22
问题 I have an angular service that returns a promise for data obtained from a server. This data is requested multiple times in a fixed interval to keep the display up to date. The response can sometimes be quite slow (up to 10 seconds), and if two requests overlap and the first one responds last I'll get out of date information displayed in the app. The timelines would be something like: - first request Req ---------------------> Res - second request Req -------> Res Currently I keep a counter of

Implementing extension method WebRequest.GetResponseAsync with support for CancellationToken

我与影子孤独终老i 提交于 2019-11-27 21:24:32
问题 The idea here is simple, but the implementation has some interesting nuances. This is the signature of the extension method I would like to implement in .NET 4 . public static Task<WebResponse> GetResponseAsync(this WebRequest request, CancellationToken token); Here is my initial implementation. From what I've read, the web request might need to be cancelled due to a timeout. In addition to the support described on that page, I want to properly call request.Abort() if cancellation is