task

Is there a proper way to cancel an asynchronous task?

社会主义新天地 提交于 2020-02-06 04:27:05
问题 I encountered a problem how to properly cancel an asynchronous task. Here is some draft. My entry point runs two asynchronous task. The first task does some 'long' work and the second one cancels it. Entry point: private static void Main() { var ctc = new CancellationTokenSource(); var cancellable = ExecuteLongCancellableMethod(ctc.Token); var cancelationTask = Task.Run(() => { Thread.Sleep(2000); Console.WriteLine("[Before cancellation]"); ctc.Cancel(); }); try { Task.WaitAll(cancellable,

Android AsyncTask-like functionality in C# (.NET)

廉价感情. 提交于 2020-02-02 11:11:26
问题 As you might know, Android's SDK features a AsyncTask class which allows for code execution on a separate thread and result acquisition in the main (UI) thread. In short, something like this: class AsyncTask { void onPreExecute(...) { //Executed on the main thread BEFORE the secondary thread gets to work on anything. } void execute(...) { //This runs on the secondary thread. } void onPostExecute(...) { //This runs on the main thread AFTER the secondary thread finishes work. You get the result

Android AsyncTask-like functionality in C# (.NET)

笑着哭i 提交于 2020-02-02 11:10:16
问题 As you might know, Android's SDK features a AsyncTask class which allows for code execution on a separate thread and result acquisition in the main (UI) thread. In short, something like this: class AsyncTask { void onPreExecute(...) { //Executed on the main thread BEFORE the secondary thread gets to work on anything. } void execute(...) { //This runs on the secondary thread. } void onPostExecute(...) { //This runs on the main thread AFTER the secondary thread finishes work. You get the result

Android AsyncTask-like functionality in C# (.NET)

情到浓时终转凉″ 提交于 2020-02-02 11:10:06
问题 As you might know, Android's SDK features a AsyncTask class which allows for code execution on a separate thread and result acquisition in the main (UI) thread. In short, something like this: class AsyncTask { void onPreExecute(...) { //Executed on the main thread BEFORE the secondary thread gets to work on anything. } void execute(...) { //This runs on the secondary thread. } void onPostExecute(...) { //This runs on the main thread AFTER the secondary thread finishes work. You get the result

Polling the right way?

僤鯓⒐⒋嵵緔 提交于 2020-01-30 14:16:10
问题 I am a software/hardware engineer with quite some experience in C and embedded technologies. Currently i am busy with writing some applications in C# (.NET) that is using hardware for data acquisition. Now the following, for me burning, question: For example: I have a machine that has an endswitch for detecting the final position of an axis. Now i am using a USB Data acquisition module to read the data. Currently I am using a Thread to continuously read the port-status. There is no interrupt

Is there a method to clear all the task in an app (Android)?

…衆ロ難τιáo~ 提交于 2020-01-30 13:19:07
问题 Quick question, just want to know if i have 2 tasks in my project. Is there any way to clear both of them in a single go. This is because when i try to clear both task to quit my app, only one is clearing and the another one is still alive which prevents me from quitting the application. finishAffinity(); int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); Any suggestions to solve this ? 回答1: Yes, You could use: FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP FLAG

How to create a new Task of type Task?

こ雲淡風輕ζ 提交于 2020-01-30 13:10:12
问题 I have: async Task doWork() { Console.WriteLine("do some async work in this method"); } Task task = new Task(doWork); //line X task.Start(); task.Wait(); Line X gives a compilation error: CS0407 'Task Form1.doWork()' has the wrong return type How do I instantiate a new Task doWork ? I am able to use the following but it gives me a different set of problems. Task task = doWork(); task.Wait(); I want to avoid this second method. How do I instantiate a new Task of type async Task at line X? 回答1:

How to check scheduled tasks on a sever using vb.net?

为君一笑 提交于 2020-01-25 07:58:08
问题 So I have a bunch of servers, each with tasks scheduled with windows task scheduler. I need to make a program that will check and retrieve all the information about these tasks. But I am very lost on how to do this. I see there's a class call TaskService, but I cant figure it out. If anybody knows how to achieve this I would really appreciate the help, i'm struggling pretty hard. Thank you so much! 来源: https://stackoverflow.com/questions/59739905/how-to-check-scheduled-tasks-on-a-sever-using

Is there a method to clear all the task in an app (Android)?

爱⌒轻易说出口 提交于 2020-01-25 06:57:28
问题 Quick question, just want to know if i have 2 tasks in my project. Is there any way to clear both of them in a single go. This is because when i try to clear both task to quit my app, only one is clearing and the another one is still alive which prevents me from quitting the application. finishAffinity(); int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); Any suggestions to solve this ? 回答1: Yes, You could use: FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP FLAG

Using Task.Run() for Linq - optimization or bottleneck

≡放荡痞女 提交于 2020-01-24 20:45:09
问题 I'm in the process of trying to optimize a few older projects, making sure they're "async all the way" and won't crash under heavier loads. I've used variations of the snippet below and feel unsure if the Task.Run is an optimization or a possible bottleneck. This method gets quite heavy use in some of the larger forms. public static Task<List<SelectListItem>> ToMultipleSelectListItems<T>(this List<T> items, Func<T, string> nameSelector, Func<T, Guid> valueSelector, List<Guid> selected, Func<T