task

Compute a recursive algorithm in parallel using Task

杀马特。学长 韩版系。学妹 提交于 2019-12-20 06:11:16
问题 how do I convert this sequential recursive algorithm into a parallel recursive algorithm using tasks? public static List<int> s = new List<int>(); // random integers, array size is n public static List<int> p = new List<int>(); // random integers, array size is n public static int n = 100; public static int w = 10; static void Main(string[] args) { G1(n, w) } private static int G1(int k, int r) { if (k == 0 || r == 0) { return 0; } if (s[k - 1] > r) { return G1(k - 1, r); } return Math.Max(G1

Run a void after an async void has been completed

核能气质少年 提交于 2019-12-20 06:09:20
问题 I am encrypting a file asynchronously,and after that I want to run a void to do some logic on the encrypted file. I want the compiler wait until the file has been encrypted completely. So how can I wait for it to be completed? Have I to use "Task"? Thanks. public static async void AES_Encrypt(string path, string Password,Label lbl,ProgressBar prgBar) { byte[] encryptedBytes = null; FileStream fsIn = new FileStream (path, FileMode.Open); byte[] passwordBytes = Encoding.UTF8.GetBytes (Password)

System.InvalidOperationException with tasks in C#

时光怂恿深爱的人放手 提交于 2019-12-20 05:52:11
问题 I am trying to make my code faster by using tasks (Parallel.foreach). Here is my updated code: int intImageW, intImageH; Bitmap bmpDest = new Bitmap(1, 1); DateTime creationTime, lastWriteTime, lastAccessTime; Parallel.ForEach(strarrFileList, strJPGImagePath => { creationTime = File.GetCreationTime(strJPGImagePath); lastWriteTime = File.GetLastWriteTime(strJPGImagePath); lastAccessTime = File.GetLastAccessTime(strJPGImagePath); using (Bitmap bmpOrig = new Bitmap(strJPGImagePath)) { intImageW

convert an 2d array from rows to blocks

情到浓时终转凉″ 提交于 2019-12-20 05:22:08
问题 I am trying to work in this code for weeks. I need to convert rows and columns in a 2d array to blocks. it should work on any matrix in size n*n. (that I have been given the size of the array) for example: this: int[][] input = {{1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}} ; this is need to be the output: {{1,2,3,1,2,3,1,2,3} {4,5,6,4,5,6,4,5,6} {7,8

How to use push queues (tasks) with GAE?

淺唱寂寞╮ 提交于 2019-12-20 04:58:13
问题 My GAE application should upload several files to another server (with urlfetch usage). How to implement this with tasks with assumption that at the end of last task completion I should perform one more action? How can I know when the last task is completed? Upd . Is the following approach with Tasks correct? class Accumulator(db.Model): counter = db.IntegerProperty() def increase_counter(key): obj = db.get(key) obj.counter += 1 obj.put() def zero_counter(key): obj = db.get(key) obj.counter =

Using SalesForce's Web Service to create and set the type of a Task

烂漫一生 提交于 2019-12-20 04:09:44
问题 I am successfully creating a Task using the SalesForce API SOAP API through Java. However, my problem is that I can't seem to set the Type of it. They all default to "Call" but I really want them to be "Email". Can someone point me in the direction of where I can do this? I think it is to do with RecordTypeMapping, but i am somewhat confused as to how to use this in my Java code to look up the particular one for Task type. I feel I have got so close with this. I have the correct WSDL that is

How to change color of particular sub-task in JFreeChart Gantt Chart?

筅森魡賤 提交于 2019-12-20 02:30:54
问题 I have a Gantt Chart with 5 tasks. Each task is divided into 3 sub-tasks. I need to define different color for each sub-task, e.g. Sub-task1: "light blue", Sub-task2: "blue", Sub-task3: "dark blue". I tried to google some examples, but I didn't find any full working example. Thanks. Update#1: I'm using IntervalCategoryDataset for the dataset. IntervalCategoryDataset dataset = createDataset(data); final Task t = new Task("Resource " + i, date(time11), date(time14)); t.addSubtask(new Task(

ContinueWith a cancelled Task

不羁岁月 提交于 2019-12-19 16:13:24
问题 I have defined the following Task var t = Task.Factory.StartNew( () => LongRunningMethod( cancellationToken ), cancellationToken ); t.ContinueWith( Callback, cancellationToken, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext() ); Inside the LongRunningMethod , I check if the cancellation token has a cancellation requested, and if so, I return from the method. That much works fine. However, the Callback does not get called in this scenario. The callback does get

How to delay 'hot' tasks so they can processed in a set order

有些话、适合烂在心里 提交于 2019-12-19 11:19:50
问题 Say I have a set of tasks: var task1 = DoThisAsync(...); var task2 = DoThatAsync(...); var task3 = DoOtherAsync(...); var taskN... I am looking for a way to process a set of tasks in order (determined by place in containing collection say), but to have the tasks only run/start when its their turn and not before - and have all of that wrapped up in its own task. Problem constraints / details are: These tasks need to be performed in a certain order i.e.task1, task2,... The previous task must

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

﹥>﹥吖頭↗ 提交于 2019-12-19 08:33:28
问题 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