task

Process.Exited not reached when running in Task.Run

Deadly 提交于 2019-12-13 00:26:20
问题 I am having a problem getting the Process.Exited event to fire when I run the process using a Task.Run in a WPF app. If this getting this Exited event is out of the questions due to the process class limitation, I would like to to update the TextBox.Text when the task is complete. I tried ContinueWith without any luck either async private void Select_Click(object sender, RoutedEventArgs e) { CancellationToken ct = new CancellationToken(); CancellationTokenSource cts = new

MainThread blocks when executing a task that interacts with COM

跟風遠走 提交于 2019-12-13 00:07:27
问题 I want to execute some long lasting tasks in a C# gui application (Windows Forms based). I first tried to execute these in parallel with Task.Factory.StartNew() . The tasks involve COM interaction. When I execute the task (which should have been executed in parallel) the main/gui thread shows the busy cursor and does not respond. The object through which the COM calls are made was created in the main thread which uses the single threaded apartment. In these posts: Blocking method of an STA

lock vs Interlocked.Exchange

邮差的信 提交于 2019-12-12 18:36:04
问题 I have an application which constantly (+-100ms) reads orders from a PLC and then puts them in a model which then gets read by multiple clients. For this im using the lock statement. Order Reading thread : lock (model) { //update object } Clients Reading : lock (model) { //serialize object to json string } send over tcp stream to client. But i could also use for the update : Interlocked.ExChange(oldObj, newObj) I don't want my clients to have to wait for a lock that is happening in the Order

How to create and implement interfaces for operations that are only sometimes async

旧时模样 提交于 2019-12-12 17:44:31
问题 Let's say I have 100s of classes that implement a common interface with a method "calculate". Some of the classes will execute async (e.g. read a file), and other classes implementing the same interface will execute code that is sync (e.g. adding two numbers). What is a good way to code this, for maintenance and for performance? The posts I read so far, always recommend to make async/await methods bubble up to the callers. So if you have one operation that is async, make the caller async,

Using .NET (3.5) Task Parallel Library in C++/ CLI

人盡茶涼 提交于 2019-12-12 17:27:34
问题 Well, I download Reactive Extensions for NET 3.5 to use it in visual studio 2008 with c++/cli... But all Task Parallel Library examples are in C#...I can not able to figure out EVEN converting that simple C# statements into C++/ CLI... // use an Action delegate and a named method Task task1 = new Task(new Action(printMessage)); // use a anonymous delegate Task task2 = new Task(delegate { printMessage(); }); How can i write those statements in C++/CLI? Best Wishes 回答1: #include "stdafx.h"

JavaFX - Cancel Task doesn't work

泪湿孤枕 提交于 2019-12-12 17:02:34
问题 In a JavaFX application, I have a method which takes a long time on large input. I'm opening a dialog when it is loading and I'd like the user to be able to cancel/close out the dialog and the task will quit. I created a task and added its cancellation in the cancel button handling. But the cancellation doesn't happen, the task doesn't stop executing. Task<Void> task = new Task<Void>() { @Override public Void call() throws Exception { // calling a function that does heavy calculations in

javafx 8 dialog and concurrency

☆樱花仙子☆ 提交于 2019-12-12 16:37:32
问题 I want to show a custom JavaFX 8 dialog to a user, capture data from the user and then close the dialog after the data is saved to the database (or shows an error message\alert). At the moment, the dialog is shown with the following code: Optional<MyType> result = dialog.showAndWait(); Followed by code: myrepository.save(result) From reading the documentation, it looks like instead I should perform this repository.save in a background Task? It looks like this code could only be executed after

Task.Factory.StartNew invoked on UI thread anyhow

自作多情 提交于 2019-12-12 15:52:21
问题 I have to deal with a strange problem, at least from my point of view. I use a Task to wait untill a variable gets a specific value and then run the Continue part on the ui thread again. Problem now is that before I call StartNew() and inside the call the ManagedThreadId is the same and it freezes my UI. Here my code: // ManagedThreadId here Task.Factory.StartNew(() => { // and here are the same. while (isClosing) { Thread.Sleep(50); } }).ContinueWith((finishedTask) => { if (currentContainer

How can I convince powershell (run through task scheduler) to find my network drive?

一笑奈何 提交于 2019-12-12 14:13:38
问题 I have a simple powershell script on windows 7 that doesn't work properly. (this is not an issue on XP) get-psdrive When I run it directly, I get Name Used (GB) Free (GB) Provider Root ---- --------- --------- -------- ---- A FileSystem A:\ Alias Alias C 12.30 11.60 FileSystem C:\ cert Certificate \ D FileSystem D:\ Env Environment Function Function HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE **Q 1486.63 289.41 FileSystem Q:\** Variable Variable WSMan WSMan When I run

How to cancel a task from different class

做~自己de王妃 提交于 2019-12-12 13:13:08
问题 I want to cancel a task started by one class from some other class. Below is an example program where i have two classes and want to cancel the task from different class. Cancellation token doesn't seem to work. namespace threadingiwthcancel { class ThreadExample { public async Task PrintSomething(CancellationToken token) { int i = 0; while (true) { if (token.IsCancellationRequested) { Console.WriteLine("Cancel requested"); break; } await Task.Delay(TimeSpan.FromSeconds(1)); Console.WriteLine