task

Passing a Func<int, int> to Task.Run() in C# without using lambda expressions

天涯浪子 提交于 2020-01-06 08:04:09
问题 I try to get my head around the Task/Func/Action/await functionality of C# but still need your help: I have a button click event handler in my gui thread that, when called, does the following: Func<int> t = new Func<int>(CountToBillion); int result = await Task.Run(t); //do something with result value... The method itself is declared as: private int CountToBillion() { //count to 1 billion and return 0 } So far, this runs without error. But if I want to pass a parameter to CountToBillion()

Illegal declaration in task definition

半世苍凉 提交于 2020-01-06 01:45:14
问题 I have the following task specification: with Ada.Real_Time; use Ada.Real_Time; package pkg_task is task type task_t is activationTime : constant Integer := 1; period : constant Integer := 2; computingTime : constant Integer := 1; startingTime : Time; end task_t; end pkg_task; When I compile I obtain the error mentioned on the title in all the lines of the task specification where I declare the variables, and I don't know what is the problem. 回答1: As Jacob wrote, you can't export anything

JavaFX make bar chart changing bars with delay in UI Thread

家住魔仙堡 提交于 2020-01-05 07:32:30
问题 I got JavaFX main thread, there I create new Thread that extends Task and sort and replace bars. Everyhing is good, but I want to make some delays(like 100ms) while replacing to show step by step sorting, maybe with animation. The problem is when I use Thread.sleep() or TranslateTransition() it just sum all delays miliseconds together in one big delay that happens before changing bars. How can I make delay that will work properly in UI thread? In main class: Sorting sorting = new Sorting();

How can I dynamically set the location of an Execute Package Task in SSIS

浪子不回头ぞ 提交于 2020-01-05 05:26:08
问题 I'm trying to set up a 'master' SSIS Package in SQL Server 2008 to run other 'child' packages. When developing the 'child' packages we have all the packages sitting on disk so we can easily debug them, so we use file connectors during development and can monitor the progress nicely. When we deploy, we deploy the child packages to SSIS on SQL Server and then go through and change all the Execute Package Task's to use a location value of 'SQL Server' and set the PackageName. Once done, we

Task.Run takes much time to start the task

那年仲夏 提交于 2020-01-05 04:59:12
问题 In my program i have ~40 running task, defined like: private void StartTryReconnectTask() { TryReconnectCTKS = new CancellationTokenSource(); TryReconnectTask = new Task(this.TryReconnect, TryReconnectCTKS.Token); TryReconnectTask.Start(); } Inside TryReconnect() there is an infinite while loop that stops only when the task is cancelled. everything seems fine to me here. Then i need to start a task (not infinite) on a button click: private void ExecuteRepairCommand(object o) { Task.Run(() =>

TcpClient.NetworkStream Async operations - Canceling / Disconnect

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 04:33:06
问题 Disclaimer: My C# isn't even close to as good as my C++ I am trying to learn how to do async sockets in C# in order to write a test app for a component of mine. I read about a variety of methods, but it seems the most modern is to use TcpClient, get the NetworkStream from it, and call async methods on the NetworkStream that return Task. So, I set off on my adventure. It is not clear how to cancel the async methods properly or if I need to. Am I supposed to manually cancel them when I want to

Real purpose of providing TaskScheduler option through ParallelOptions parameter in Parallel class APIs

坚强是说给别人听的谎言 提交于 2020-01-04 14:00:56
问题 I have a windows C# WinForms application. I'm confused by the way the default task scheduler is behaving for parallel class in task parallel library. When I call Parallel.For inside ParallelForEach method I was expecting the numbers to get printed in jumbled fashion in output window through Console.WriteLine statement inside "Method1" method. Since I'm not passing any ParallelOptions to configure the scheduler for Parallel class it should be using default task scheduler but numbers are

How to catch exception from ReactiveCommand?

老子叫甜甜 提交于 2020-01-04 07:43:13
问题 I know how to handle exceptions thrown by async tasks called by ReactiveCommand<T> but how do I handle an exception that is thrown before the task is returned? In the following example ThrowAndHandle command will throw an exception from the async task when executed and the exception will be handled. The command ThrowButFailToHandle demonstrates that I can not use ThrownExceptions to handle an exception that does not occurr "in" the task but rather before the task is created. How can such an

How to catch exception from ReactiveCommand?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 07:43:06
问题 I know how to handle exceptions thrown by async tasks called by ReactiveCommand<T> but how do I handle an exception that is thrown before the task is returned? In the following example ThrowAndHandle command will throw an exception from the async task when executed and the exception will be handled. The command ThrowButFailToHandle demonstrates that I can not use ThrownExceptions to handle an exception that does not occurr "in" the task but rather before the task is created. How can such an

Call async method from sync action methods: Task.Run or ConfigureAwaits(false)

别说谁变了你拦得住时间么 提交于 2020-01-04 05:14:56
问题 I can prevent deadlock for Result call for async Task in sync action method of controller using both: ConfigureAwaits(false) on Task or using Task.Run . In both cases async method will be completed on thread from threadpool. Controller source: public class TestController : Controller { /// <summary> /// Thread from threadpool will be used to finish async method. /// </summary> public string TaskRun() { return Task.Run(GetStatus).Result + " <br/> " + Thread.CurrentThread.ManagedThreadId + " -