parallel-extensions

WCF Parallel Impersonation

本秂侑毒 提交于 2019-12-07 09:16:25
问题 I have a WCF service with "ImpersonationOption.Required". The impersonation does not seem to flow through when using parallelism. For example: Parallel.ForEach(items => results.Add(SystemUtil.WindowsUser.Name) Will return a number with the impersonated user, and a number with the app pool user. Can impersonation be made to work with parallelism? Best, Marc Update: This is actual code on the IIS Service side. [OperationBehavior(Impersonation = ImpersonationOption.Required)] public string[]

Correct way to guarantee thread safety when adding to a list using Parallel library

旧街凉风 提交于 2019-12-07 08:21:45
问题 I loop over an array of connection strings and on each loop I extract some information and add to the list. Now, I want to use Parallel library to make it multithreaded, but I'm not sure if the library guarantees that writes to the list would be thread-safe or whether I need to use locking: List<SomeType> list = new List<SomeType>(); settings.AsParallel().ForAll(setting => { list.AddRange(GetSomeArrayofSomeType(setting)); /// DO I NEED TO DO LOCKING HERE??? }) 回答1: Write's to the list are

Task Parallel Library - How do you get a Continuation with TaskContinuationOptions.OnlyOnCanceled to Fire?

让人想犯罪 __ 提交于 2019-12-07 07:20:53
问题 I'm experimenting with the Task support in .NET 4.0 - specifically with the continuation support. What I'm perplexed about is that I can't figure out how to get a continuation with the TaskContinuationOptions.OnlyOnCanceled flag set to execute. If I do a ThrowIfCancellationRequested in my worker routine, it only seems to propagate out of the continuation as a fault instead of a cancel operation. For instance, given this code: using System; using System.Threading; using System.Threading.Tasks;

Using Parallel Linq Extensions to union two sequences, how can one yield the fastest results first?

给你一囗甜甜゛ 提交于 2019-12-06 21:12:19
问题 Let's say I have two sequences returning integers 1 to 5. The first returns 1, 2 and 3 very fast, but 4 and 5 take 200ms each. public static IEnumerable<int> FastFirst() { for (int i = 1; i < 6; i++) { if (i > 3) Thread.Sleep(200); yield return i; } } The second returns 1, 2 and 3 with a 200ms delay, but 4 and 5 are returned fast. public static IEnumerable<int> SlowFirst() { for (int i = 1; i < 6; i++) { if (i < 4) Thread.Sleep(200); yield return i; } } Unioning both these sequences give me

In parallel call, limit executions per second

雨燕双飞 提交于 2019-12-06 03:34:51
Using TPL / Parallel.ForEach is there an out-of-the-box way to limit the number of times a method is called per unit of time (i.e. no more than 50 calls per second). This is different than limiting the number of threads. Perhaps there's some simple hack to make this work? SFun28 One solution is to make a thread-safe version of the following https://stackoverflow.com/a/7728872/356790 /// <summary> /// This class limits the number of requests (method calls, events fired, etc.) that can occur in a given unit of time. /// </summary> class RequestLimiter { #region Constructors /// <summary> ///

Using Parallel Extensions with ThreadStatic attribute. Could it leak memory?

我们两清 提交于 2019-12-06 01:54:10
问题 I'm using Parallel Extensions fairly heavily and I've just now encountered a case where using thread local storage might be sensible to allow re-use of objects by worker threads. As such I was looking at the ThreadStatic attribute which marks a static field/variable as having a unique value per thread. It seems to me that it would be unwise to use PE with the ThreadStatic attribute without any guarantee of thread re-use by PE. That is, if threads are created and destroyed to some degree would

Correct way to guarantee thread safety when adding to a list using Parallel library

我的梦境 提交于 2019-12-05 17:26:42
I loop over an array of connection strings and on each loop I extract some information and add to the list. Now, I want to use Parallel library to make it multithreaded, but I'm not sure if the library guarantees that writes to the list would be thread-safe or whether I need to use locking: List<SomeType> list = new List<SomeType>(); settings.AsParallel().ForAll(setting => { list.AddRange(GetSomeArrayofSomeType(setting)); /// DO I NEED TO DO LOCKING HERE??? }) Write's to the list are indeed not safe for multithreaded writes. You need to either use a lock to synchronize access or use a

WCF Parallel Impersonation

半城伤御伤魂 提交于 2019-12-05 16:04:28
I have a WCF service with "ImpersonationOption.Required". The impersonation does not seem to flow through when using parallelism. For example: Parallel.ForEach(items => results.Add(SystemUtil.WindowsUser.Name) Will return a number with the impersonated user, and a number with the app pool user. Can impersonation be made to work with parallelism? Best, Marc Update: This is actual code on the IIS Service side. [OperationBehavior(Impersonation = ImpersonationOption.Required)] public string[] WhoAmI(int numOfTests) { var tests = new List<int>(); for (var i = 0; i < numOfTests; i++) tests.Add(i);

Parallel Extensions

谁说我不能喝 提交于 2019-12-05 01:01:57
问题 I have an application with heavy IO operations such as file copying, zipping and moving the files around the file system, copying to backup servers. I build this program as single threaded. It runs in 2 minutes. I built another version of this program with Parallel extensions and using Task, which runs almost in 2 minutes as well. In other words I didnt see a performance gain by using Parallels due to heavy IO. Would I get the same results if i deploy the application to a blade server? Does

Parallel Brute-Force Algorithm

限于喜欢 提交于 2019-12-04 17:03:38
So I was looking at http://codahale.com/how-to-safely-store-a-password/# and became curious how fast different hash could be bruteforced on a somewhat powerful desktop computer and was tempted to test it Most of the algorithms I've seen though are single-threaded and it struck me that this would be a really interesting challenge in using c# 4.0 Parallel.net/Plinq extensions and concurrent structures (like ConcurrentBag and IProducerConsumer). So my task is as follows, build the most efficient/performant bruteforce checker of a password of n-length and charset[x] using parallelization, ie