task

Run background work, but ensure that this can only run once at any given time [duplicate]

℡╲_俬逩灬. 提交于 2020-01-17 08:45:08
问题 This question already has answers here : Check if task is already running before starting new (4 answers) Closed 2 years ago . I want to kick off some background work, I do not have to keep any reference. Start and forget. However I want to make sure that this background work is only running once at any time given. Assuming that StartBackgroundWork is only ever called from one thread, can you improve this solution? Do you see any problems with this? private bool _busy; private void

Share collections between tasks within c# application

为君一笑 提交于 2020-01-17 04:22:24
问题 I have a wpf application in which I have to fill some Collection : private async Task FillList() { await Task.Factory.StartNew(() => { gdpList = SimpleIoc.Default.GetInstance<ICrud<gdp_groupe>>().GetAll().ToList(); MedecinGDP.AddRange(SimpleIoc.Default.GetInstance<ICrud<vue_medecin>>().GetAll()); CodeGDP_Collection.AddRange(gdpList); FiltredParticipant.AddRange(SimpleIoc.Default.GetInstance<ICrud<fsign_fiche>>().GetAll()); }); } The problem is that the collections still empty after I call

Task.Run( () MethodName()) and await Task.Run(async () => MethodName())

蓝咒 提交于 2020-01-16 20:07:53
问题 I am trying to understand if using await Task.Run(async () => MethodName()) in MVC 5 gives the benefits of freeing up the thread of a long running IO operation, while continuing with other code tasks in Parallel. I know that simply using "await MethodName()" will free up the thread, but it will not move to the next line of code unit MethodName() is done executing. (Please correct me if I am wrong). I'd like to be able to free up the thread while the async operation is executing, as well as

Task.Run( () MethodName()) and await Task.Run(async () => MethodName())

╄→гoц情女王★ 提交于 2020-01-16 20:07:03
问题 I am trying to understand if using await Task.Run(async () => MethodName()) in MVC 5 gives the benefits of freeing up the thread of a long running IO operation, while continuing with other code tasks in Parallel. I know that simply using "await MethodName()" will free up the thread, but it will not move to the next line of code unit MethodName() is done executing. (Please correct me if I am wrong). I'd like to be able to free up the thread while the async operation is executing, as well as

How to combine same code of different tasks

心不动则不痛 提交于 2020-01-16 18:18:32
问题 This question is related to Apply same configurations to different tasks In gradle, I have this piece of configuration: idea { module { excludeDirs -= file("$buildDir/") sourceDirs += file(generatedSrcDir) } } I have another one for eclipse with same code. Question: idea, eclipse { module { excludeDirs -= file("$buildDir/") sourceDirs += file(generatedSrcDir) } } is this possible ? 回答1: What you need to do would be written as the following: apply plugin: 'idea' apply plugin: 'eclipse' ext

How do I deal without ByRef in an Async function?

会有一股神秘感。 提交于 2020-01-16 03:34:13
问题 I'm working on replacing my old code that uses threads to a .NET 4.5 Task based system. I have the following sub that I wish to convert; Public Function Delay(Milliseconds As Integer, ByRef Job As Job) As Boolean For i As Integer = 1 To CInt(Milliseconds / 100) Thread.Sleep(100) If Job.IsCancelled Then Return True Next Return False End Function The Job class is one of my own, but importantly it contains an integer which is set to 1 if the job should be cancelled. So, the Delay function allows

Ada left hand of assignment must not be limited type

拈花ヽ惹草 提交于 2020-01-15 12:14:26
问题 I am at loss after spending hours on this. Protected type declaration: protected type AdditionMachine is procedure setTask (Item : in WorkerTask); procedure getTask (Item : out WorkerTask); procedure calculate; private machineType : String (1 .. 1) := "A"; job : workerTask; end AdditionMachine; Task: task body SimpleTask1 is Available : Natural := ADDITION_MACHINES; Elements : array (1 .. ADDITION_MACHINES) of AdditionMachine; begin loop select when Available > 0 => accept getMachine (machine

Is Task.ContinueWith thread safe?

非 Y 不嫁゛ 提交于 2020-01-15 06:18:42
问题 I have multiple threads that enqueue actions to the same task using ContinueWith() Is it thread safe? Or should I wrap it with some dedicated lock? 回答1: It is thread safe. It even works when the task has already completed. 来源: https://stackoverflow.com/questions/31165280/is-task-continuewith-thread-safe

Is Task.ContinueWith thread safe?

坚强是说给别人听的谎言 提交于 2020-01-15 06:17:57
问题 I have multiple threads that enqueue actions to the same task using ContinueWith() Is it thread safe? Or should I wrap it with some dedicated lock? 回答1: It is thread safe. It even works when the task has already completed. 来源: https://stackoverflow.com/questions/31165280/is-task-continuewith-thread-safe

Task behaviour differs from Task<T> behaviour when OperationCanceledException thrown

拥有回忆 提交于 2020-01-15 05:04:07
问题 Why does this test fail? The only difference between t1 and t2 , as far as I can tell, is that t1 is a Task , and t2 is a Task<int> . Yet for some reason t2 ends up in the Faulted status, as opposed to the Canceled status. Why would the behavior differ? [Test] public void Test_foo() { var t1 = Task.Run(() => { throw new OperationCanceledException(); }); try { t1.Wait(); } catch (AggregateException e) { Assert.IsTrue(t1.IsCanceled); } var t2 = Task.Run(() => { throw new