task

Javafx Updating UI from a Thread without direct calling Platform.runLater

不羁岁月 提交于 2019-12-19 08:33:14
问题 Nowadays some says it is not suitable to use Platform.runLater() for updating the UI from a non-JavaFX Thread and Oracle site introduce a way with bindings for progress bar updating. Here I want to update a Label, so coded it like this: Task task = new Task() { @Override protected Object call() throws Exception { int i = 0; while (true) { this.updateMessage("Count " + i); System.out.println(i); // Thread.sleep(10); i++; } } }; Thread t = new Thread(task); lbStatus.textProperty().bind(task

Async and asynchronous methods clarification?

女生的网名这么多〃 提交于 2019-12-19 04:23:49
问题 AFAIK - ( and I read a lot about it), asynchronous methods ( not asynchronous delegates !) exists to solve the "thread is blocked" problem when dealing with I/O operations like : reading a file or downloading a file : Richter shows it quite clearly here : Task<T> is not related to the i/o blocking issue. it is simply just like open a thread ( plus extra efficiency + functionality ) - but it still causes a thread to consume cpu quanta etc. And here is my question : I've read (msdn) that : An

C# in Async Task change Label Text

主宰稳场 提交于 2019-12-19 04:10:52
问题 The following Code does not change the Text and stops executing the Task private void button1_Click(object sender, EventArgs e) { label1.Text = "Test"; Task.Run(() => MyAsyncMethod()); } public async Task MyAsyncMethod() { label1.Text = ""; //everything from here on will not be executed } would be really handy if you could use async together with the UI 回答1: for accessing a GUI control through a second thread you need to invoke. following example shows how to set a label's text properly

In Linux, schedule task to Hour, minute, second precision [duplicate]

醉酒当歌 提交于 2019-12-19 04:09:40
问题 This question already has an answer here : Linux task schedule to Hour, minute, second (1 answer) Closed 5 years ago . I just want to run a shell scrip at say this exact time "16:22:36". utilities like "at" are useless since they don't have "seconds". "sleep" does not work since the loop is ending 8 hours ahead of time for some reason :s , I have searched all over google and couldn't find any tools. so a huge Os like Linux doesn't have a proper task scheduler? 回答1: The standard cron lacks

How to wait until all tasks finished without blocking UI thread?

Deadly 提交于 2019-12-19 04:03:02
问题 In the following code I disable button before processing tasks and would like to enable it after all tasks are finished. List<Task> tasks = new List<Task>(); buttonUpdateImage.Enabled = false; // disable button foreach (OLVListItem item in cellsListView.CheckedItems) { Cell c = (Cell)(item.RowObject); var task = Task.Factory.StartNew(() => { Process p = new Process(); ... p.Start(); p.WaitForExit(); }); task.ContinueWith(t => c.Status = 0); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); //

Kinect Frame Arrived Asynchronous

坚强是说给别人听的谎言 提交于 2019-12-19 03:33:28
问题 I am looking for some help with my MultiSourceFrameArrived event in the Kinect v2 SDK. The following is the method in question: private async void _reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame(); using (var colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame()) { if (colorFrame != null) { _writeableBitmap.Lock(); colorFrame.CopyConvertedFrameDataToIntPtr( _writeableBitmap

Kinect Frame Arrived Asynchronous

拜拜、爱过 提交于 2019-12-19 03:32:38
问题 I am looking for some help with my MultiSourceFrameArrived event in the Kinect v2 SDK. The following is the method in question: private async void _reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame(); using (var colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame()) { if (colorFrame != null) { _writeableBitmap.Lock(); colorFrame.CopyConvertedFrameDataToIntPtr( _writeableBitmap

Thread.Sleep(2500) vs. Task.Delay(2500).Wait()

二次信任 提交于 2019-12-19 02:39:21
问题 I want some clarity on this. I know that Task.Delay will internally use a Timer and it is obviously task-based (awaitable), whereas Thread.Sleep will cause the thread to be blocked. However, does calling .Wait on the task cause the thread to be block? If not, one would assume that Task.Delay(2500).Wait() is better than Thread.Sleep(2500) . This is slightly different that the SO question/answer here as I'm calling .Wait() . 回答1: Using Wait on an uncompleted task is indeed blocking the thread

Run work on specific thread

谁说我不能喝 提交于 2019-12-19 02:28:30
问题 I would like to have one specific thread, queue for Tasks and process tasks in that separate thread. The application would make Tasks based on users usage and queue them into task queue. Then the separate thread processes the tasks. It is vital to keep the thread alive and use it for processing queued tasks even if queue is empty. I have tried several implementations of TaskScheduler with BlockingCollection and limit the concurrency to only one thread but it seems the Thread gets disposed

Task.WhenAll not waiting

 ̄綄美尐妖づ 提交于 2019-12-19 02:05:19
问题 I am learning how to use async functions in console application but can't make the Task.WhenAll wait until all tasks are completed. What is wrong with the following code? It works synchronously. Thank you in advance. static void Main(string[] args) { ... IncluiValores(...); ... } static async void IncluiValores(...) { Task<List<int>> res1 = att.GetAIDBAPI(att); Task<List<int>> res2 = att.GetAIDBAPI(att2); List<int>[] res = await Task.WhenAll(res1, res2); ... } UPDATE - Function Definition: