task

Mixing async/await with Result

微笑、不失礼 提交于 2020-01-01 04:43:05
问题 Let me just preface this question with a few things: I've read several SO questions saying that you should not do this (such as How to safely mix sync and async code) I've read Async/Await - Best Practices in Asynchronous Programming again saying you shouldn't do this So I do know that this is not a best practice, and don't need anyone telling me such. This is more of a "why does this work" question. With that out of the way, here is my question: I've written a small GUI application that has

How to know if my application is in foreground or background, android?

孤街浪徒 提交于 2019-12-31 10:04:16
问题 I need to check if my application is running in background or foreground and then perform some operations relatively to it. I searched a lot and a clear solution is not available. Make a parent activity in its onPause() and onResume() methods keep some variable to update them accordingly. When you create any new activity inherit your parent activity. Although this is the best solution I feel to achieve my task, but sometimes if the power button is clicked even though application is in

How to know if my application is in foreground or background, android?

偶尔善良 提交于 2019-12-31 10:04:10
问题 I need to check if my application is running in background or foreground and then perform some operations relatively to it. I searched a lot and a clear solution is not available. Make a parent activity in its onPause() and onResume() methods keep some variable to update them accordingly. When you create any new activity inherit your parent activity. Although this is the best solution I feel to achieve my task, but sometimes if the power button is clicked even though application is in

C# “Local” variable loaded inside a task won't keep its value when called outside the task

我是研究僧i 提交于 2019-12-31 07:32:12
问题 I'm running in circles with this one. I have some tasks on an HttpClient (.NET 4 with httpclient package from NuGet), in one of them i'm trying to assign a value to a variable that i declared OUTSIDE the task, at the beggining of the function, but when the execution gets to that point, the variable lost the assigned value and came back to the initial value, like it never changed. But I'm pretty sure it DID change at a moment, when the execution passed through the task. I've made this

C# “Local” variable loaded inside a task won't keep its value when called outside the task

核能气质少年 提交于 2019-12-31 07:31:05
问题 I'm running in circles with this one. I have some tasks on an HttpClient (.NET 4 with httpclient package from NuGet), in one of them i'm trying to assign a value to a variable that i declared OUTSIDE the task, at the beggining of the function, but when the execution gets to that point, the variable lost the assigned value and came back to the initial value, like it never changed. But I'm pretty sure it DID change at a moment, when the execution passed through the task. I've made this

PhpStorm Startup task - php artisan serve

淺唱寂寞╮ 提交于 2019-12-31 02:55:46
问题 I am working with a project locally and I want to run "php artisan serve" with the PhpStorm's startup task feature every time I start the project. I went to Settings -> Tools -> Startup Tasks and clicked the green plus, then Add New Configuration . However, I don't know what to choose from there. There is no "artisan" option there. How should I do it? 回答1: Artisan is a php script so you can simply add a new PHP Script task: File: Browse to you project directory and select artisan . Arguments:

Parallelization of CPU bound task continuing with IO bound

两盒软妹~` 提交于 2019-12-31 02:20:27
问题 I'm trying to figure out a good way to do parallelization of code that does processing of big datasets and then imports the resulting data into RavenDb. The data processing is CPU bound and database import IO bound. I'm looking for a solution to do the processing in parallel on Environment.ProcessorCount number of threads. The resulting data should then be imported into RavenDb on x (lets say 10) pooled threads in parallel with the above process. The main thing here is I want the processing

Is it possible to await an IO operation that is not declared as async? If not, what should I do?

倖福魔咒の 提交于 2019-12-31 01:47:49
问题 I'm new to asynchronous programming in C# and I'm still confused about a few things. I've read that after .NET 4.5, the APM and EAP are no longer recommended for new development since the TAP is supposed to replace them (source). I think I understood how async/await works and I'd be able to use them for performing IO operations that have async methods. For example, I could write an async method that awaits for an HttpWebClient's GetStringAsync result, since it's declared as an async method.

ContinueWith a Task on the Main thread

Deadly 提交于 2019-12-31 00:51:02
问题 Forgive me if this is a simple question; I couldn't phrase it in a generic enough way to search for the answer. Consider this code: var task = Task.Factory.StartNew(() => Whatever()); task.ContinueWith(Callback, TaskScheduler.FromCurrentSynchronizationContext()) How exactly is it determined when the callback method will execute? Will it wait until the main thread is currently finished doing whatever it is doing, or will it get called immediately after the asynchronous call is complete? And

Task.WaitAll freezes app C#

半城伤御伤魂 提交于 2019-12-30 10:25:45
问题 I wanted to try out Threading.Task (C#) to run some work in parallel. In this simple example I have a form with progress bar and button. On click the RunParallel function is called. Without Task.WaitAll() it seems to run through fine. However, with the WaitAll statement the form shows and nothing happens. I dont understand what I am doing wrong in the setup below. Thanks in advance. public partial class MainWindow : Form { public delegate void BarDelegate(); public MainWindow() {