multithreading

How to call a completion method everytime ThreadPool.QueueUserWorkItem method is returned

帅比萌擦擦* 提交于 2020-01-24 00:55:06
问题 I am using System.Threading.ThreadPool.QueueUserWorkItem(x => MyMethod(param1, param2, param3, param4, param5)); I want to call the following method from the main thread every time the call to MyMethod is completed: UpdateGui() { } How do I do that? Thanks! 回答1: Keep a global counter of work items queued and an object to protect it: int runningTasks = 0; object locker = new object(); Every time a task is added increment the counter: lock(locker) runningTasks++; System.Threading.ThreadPool

How can I make sure my threads / processes are running on different cores

∥☆過路亽.° 提交于 2020-01-23 18:58:07
问题 I'm trying to measure performance improvement of my code when I run my multithreaded android app on a multicore device (like the S3) versus a single core android device. To measure performance, I run the tasks sequentially versus in parallel. I've implemented normal Java threads, which didn't seem to make a difference. I thus tried AsynchTask, but I only got a little bit of performance improvement. Can you let me know how I can write code that makes sure that each of my tasks / threads are

c# excel beforesave thread

你说的曾经没有我的故事 提交于 2020-01-23 17:42:08
问题 I try to create a c# excel 2007 Add-In, and i want to do "faster" the "beforeSave" method. I simply use a thread (and try the task and task.factory too) but its always say same error. The code. private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WorkbookBeforeSave += new Microsoft.Office.Interop.Excel.AppEvents_WorkbookBeforeSaveEventHandler(Application_WorkbookBeforeSave); }// thisAddIn_startup method end public void Application_WorkbookBeforeSave(Microsoft

Calling WaitForSingleObject from C#

余生颓废 提交于 2020-01-23 17:15:49
问题 I am trying to call WaitForSingleObject method from C#, as documented here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx In order to call this function I need to create a Handle, or I need to get a Handle of type IntPtr, how can it be done? I've tried this function that I found: http://www.pinvoke.net/default.aspx/kernel32.WaitForSingleObject [DllImport("coredll.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]

Understanding `memory_order_acquire` and `memory_order_release` in C++11

末鹿安然 提交于 2020-01-23 17:12:06
问题 I'm reading through the documentation and more specifically memory_order_acquire : A load operation with this memory order performs the acquire operation on the affected memory location: no reads or writes in the current thread can be reordered before this load. All writes in other threads that release the same atomic variable are visible in the current thread (see Release-Acquire ordering below). memory_order_release : A store operation with this memory order performs the release operation:

Understanding `memory_order_acquire` and `memory_order_release` in C++11

本小妞迷上赌 提交于 2020-01-23 17:11:31
问题 I'm reading through the documentation and more specifically memory_order_acquire : A load operation with this memory order performs the acquire operation on the affected memory location: no reads or writes in the current thread can be reordered before this load. All writes in other threads that release the same atomic variable are visible in the current thread (see Release-Acquire ordering below). memory_order_release : A store operation with this memory order performs the release operation:

How many threads can simultaneously invoke an unsynchronized method of an object?

我是研究僧i 提交于 2020-01-23 17:09:12
问题 So let's say I have a class X with a method m. Method m is NOT synchronized and it doesn't need to be since it doesn't really change the state of the object x of type X. In some threads I call the method like this: x.m(). All these threads use the same object x. By how many threads can be this method (method m) called on object x simultaneously? Can be the fact that the method is called by, let's say, 100 threads a bottleneck for my application? thanks. 回答1: Other's have answered your direct

Java Thread.sleep waking up “much” earlier than the scheduled time

老子叫甜甜 提交于 2020-01-23 12:22:35
问题 I have a requirement of writing a daemon which initiates number of threads that wakes up at different times. The daemon is written in Java using commons apache library and is run on a Linux machine (Fedora 13 ). One thread wakes up everyday to perform task A which happens as scheduled. But there is another thread which is scheduled to wake up every Monday at 6 am to perform some task which does not happen as scheduled. The problem is that this thread wakes up much before the actual scheduled

Java Thread.sleep waking up “much” earlier than the scheduled time

大城市里の小女人 提交于 2020-01-23 12:20:03
问题 I have a requirement of writing a daemon which initiates number of threads that wakes up at different times. The daemon is written in Java using commons apache library and is run on a Linux machine (Fedora 13 ). One thread wakes up everyday to perform task A which happens as scheduled. But there is another thread which is scheduled to wake up every Monday at 6 am to perform some task which does not happen as scheduled. The problem is that this thread wakes up much before the actual scheduled

Wrapping blocking calls to be async for better thread reuse and responsive UI

孤街醉人 提交于 2020-01-23 12:16:09
问题 I have a class that is responsible for retrieving a product availability by making call to a legacy class. This legacy class itself internally collects product data by making BLOCKING network calls. Note that I cannot modify code of legacy API. Since all products are independent to each other, I would like to parallelise collecting the information without creating any unnecessary threads and also not blocking thread that gets blocked on calling this legacy API. With this background here are