task

Using Interlocked.CompareExchange to increment a counter until a value

倖福魔咒の 提交于 2019-12-22 08:39:20
问题 I need to increment a counter until it reaches a particular number. I can use two parallel task to increment the number. Instead of using a lock to check if the number has not reach the maximum allowed value and then incrementing, I thought using Interlocked.CompareExchange in the following manner: public class CompareExchangeStrategy { private int _counter = 0; private int _max; public CompareExchangeStrategy(int max) { _max = max; } public void Increment() { Task task1 = new Task(new Action

Execute repository functions in scheduler task

本小妞迷上赌 提交于 2019-12-22 05:44:45
问题 Currently I have an scheduler task, but I want to use function from my extbase repository (in the same extension). I keep getting "PHP Fatal error: Call to a member function add() on a non-object", no matter how I try to include my repo or controller from extbase. My SampleTask.php: namespace TYPO3\ExtName\Task; class SampleTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask { public function execute() { $controller = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\ExtName

C# / VB.Net Task vs Thread vs BackgroundWorker

眉间皱痕 提交于 2019-12-22 05:06:38
问题 I have "Googled" but still confused with Task, Thread, and Background Worker..... Is "Task is a high level API that running on current thread" correct ? If 1 is correct, why I need to use invoke to change the UI inside the task at same thread ? Backgroundworker only got lowest priority in the application ? So the performance of backgroundworker is lower than task and thread ? Right ? Finally, in my application I need to get a string from server using "HttpWebRequest", after that parse the

Creating and starting a task on the UI thread

拈花ヽ惹草 提交于 2019-12-22 04:56:14
问题 When a method that gets called on a worker thread needs to run code on the UI thread and wait for it to complete before doing something else, it can be done like this: public int RunOnUi(Func<int> f) { int res = Application.Current.Dispatcher.Invoke(f); return res; } But what if I wanted to do it with tasks? Is there a way for the RunOnUi method to create a task that is started on the UI and return it so that the caller (which runs on a worker thread) can wait for it? Something that will fit

Visual Studio 2015 - User tasks gone?

扶醉桌前 提交于 2019-12-22 02:03:12
问题 I've recently switched from Visual Studio 2013 to 2015 and converted all of my old projects. However, now I can't seem to find my user tasks anymore? There used to be a drop-down menu in the task list, but it looks like that's gone in the new version, unless I'm missing something. Have user tasks been removed? If so, is there a way I can still retrieve them from my project? 回答1: The documentation on MSDN has been updated with this paragraph: The user task feature has been removed in Visual

Can you GET Rally API requirements, defects, and all tasks with one query

瘦欲@ 提交于 2019-12-21 20:46:55
问题 Currently I have to make multiple GETs to receive all the information which I need User Story: FormattedID, _refObjectName, State, Owner._refObjectName Tasks for each User Story: FormattedID, _refObjectName, State, Owner._refObjectName Defect: FormattedID, _refObjectName, State, Owner._refObjectName Tasks for each Defect: FormattedID, _refObjectName, State, Owner._refObjectName For all of the User Stories I use: https://rally1.rallydev.com/slm/webservice/1.26/hierarchicalrequirement.js?query=

Re-throw exception in task (TPL) loses stack trace

邮差的信 提交于 2019-12-21 17:34:31
问题 I've code that rethrows an exception. When I later read the exception from task.Exception, its stacktrace points to the location where I re-threw the exception (line n and not line m, as I expected). Why is this so? bug in TPL or more likely something I have overlooked. As I workaround I can wrap the exception as the inner-exception in a new exception. internal class Program { private static void Main(string[] args) { Task.Factory.StartNew(TaskMethod).ContinueWith(t => Console.WriteLine(t

How can I get the children process list in kernel code

与世无争的帅哥 提交于 2019-12-21 17:23:20
问题 I want to get to the children task (process) list of a process, here is the code: void myFunc() { struct task_struct* current_task; struct task_struct* child_task; struct list_head children_list; current_task = current; children_list = current_task->children; child_task = list_entry(&children_list,struct task_struct,tasks); printk("KERN_INFO I am parent: %d, my child is: %d \n", current_task->pid,child_task->pid); } The current pid is right, but the child pid is not correct. What am I doing

Killing a deadlocked Task in .NET 4 TPL

梦想的初衷 提交于 2019-12-21 12:58:55
问题 I'd like to start using the Task Parallel Library, as this is the recommended framework going forward for performing asynchronous operations. One thing I haven't been able to find is any means of forcible Abort, such as what Thread.Abort provides. My particular concern is that I schedule tasks running code that I don't wish to completely trust. In particular, I can't be sure this untrusted code won't deadlock and therefore I can't be certain if a Task I schedule using this code will ever

Construct Task from WaitHandle.Wait

时光总嘲笑我的痴心妄想 提交于 2019-12-21 12:31:19
问题 I chose to return Task<T> and Task from my objects methods to provide easy consumation by the gui. Some of the methods simply wait for mutex of other kind of waithandles . Is there a way to construct Task from WaitHandle.Wait() so that I don't have to block one treadpool thread for that. 回答1: There is a way to do this: you can subscribe to WaitHandle using ThreadPool.RegisterWaitForSingleObject method and wrap it via TaskCompletionSource class: public static class WaitHandleEx { public static