.net-4.0

Using nested Parallel.For

∥☆過路亽.° 提交于 2019-12-07 02:27:10
问题 Consider this example: var x = 0; for (var i = 0; i < 100; i++ ) { for (var a = i+1; a < 100; a++) x += 1; } When printing x we always get 4950. What about if I want to parallelise this? This is what I come up with Parallel.For(0, 100, i => Parallel.For(i + 1, 100, a => { x += 1; })); However this does Not print 4950 each time I run it. Why? 回答1: Parallel Extensions helps you with task creation, allocation, running and rendezvous, in a near-imperative syntax. What it doesn't do is take care

Timer initialization and Race condition in c#?

笑着哭i 提交于 2019-12-07 02:27:03
问题 I saw this code on Richter's book : The following code demonstrates how to have a thread pool thread call a method starting immediately and then every 2 seconds thereafter: /*1*/ internal static class TimerDemo /*2*/ { /*3*/ private static Timer s_timer; /*4*/ public static void Main() /*5*/ { /*6*/ Console.WriteLine("Checking status every 2 seconds"); /*7*/ // Create the Timer ensuring that it never fires. This ensures that /*8*/ // s_timer refers to it BEFORE Status is invoked by a thread

WCF with 3.5 and 4.0 together

佐手、 提交于 2019-12-07 01:42:01
问题 Has anyone managed to run wcf successfully in 2.0 integrated mode on IIS7 when .net 4 has been installed? I found that installing .net 4 removed the 2.0 handlers for svc and replaced them with .net 4 versions (this led to a 404.17 error in my v3.5 site), I managed to get my 3.5 site working again by running ServiceModelReg.exe /i from the v3.0 folder (Windows Commuication Foundation) but that removed the 4.0 mappings so they seem to be mutually exclusive? any advise on how to run a 4.0 and 3

Powershell 2.0 Remoting loading a .Net 4.0 dll

喜你入骨 提交于 2019-12-07 01:13:40
问题 I am trying to load a .Net 4.0 assembly, using [Reflection.Assembly]::LoadFrom, inside of a remote Powershell 2.0 session. It works locally, due to a change I made to the powershell.exe.config file, but fails with a "This assembly is built by a runtime newer ..." exception in a remote session. Both machines involved have .Net 2.0 and 4.0, and have the powershell.exe.config change for the x86 and x64 bit powershell executables. I've also tried changing the server powershell registry keys: HKLM

How can I upgrade multiple projects (same solution) that's targeting 3.5 to 4.0 in one go?

若如初见. 提交于 2019-12-07 00:51:45
问题 In one big solution we have about 100~ projects all targeting 3.5 and currently in VS.NET 2010. Now we want to upgrade it to .NET 4.0, do I have to go one by one and change their target? or is there any way to automate this process? 回答1: When upgrading many projects and similar operation I usually use Find and replace in files. First I upgrade one project and diff the result, then I search and replace relevant parts in my .csproj files. 回答2: The Target Framework Migrator extension works great

Error CS0433 in large precompiled Asp.net Website Project

你离开我真会死。 提交于 2019-12-07 00:31:42
问题 Background I've taken over a very large asp.net website project. The old deploy process was to copy .cs, .aspx, and .ascx files to IIS and have it build on the fly. I want to precompile it and use TeamCity to automatically deploy it. I've done this with some of the other website projects. The project has about 350 user controls that are nicely organized in folders but are used all over the place. Controls referenced from other folders, from each other... Basically a circular file reference

AsParallel () and Any()?

强颜欢笑 提交于 2019-12-07 00:22:15
问题 I've seen this code which check a condition using AsParallel() and Any() : bool IsAnyDeviceConnected() { return m_devices.Any(d => d.IsConnected); } and to make it faster : bool IsAnyDeviceConnected() { return m_devices.AsParallel().Any(d => d.IsConnected); } But looking at Any() : internal static bool Any<T>(this IEnumerable<T> source, Func<T, bool> predicate) { foreach (T element in source) { if (predicate(element)) { return true; } } return false; } I don't see ( obviously ) - that it does

Casting an array of integers to an array of enums

孤街醉人 提交于 2019-12-07 00:07:59
问题 I have an enum that has 4 values: public enum DriveRates { driveSidereal = 0, driveLunar = 1, driveSolar = 2, driveKing = 3 } I have an array of values that I want to cast to an array of DriveRates. However when I do var rates = (DriveRates[])ret; , with ret being an object array of numbers (probably integers), it says Unable to cast object of type 'System.Object[]' to type 'ASCOM.DeviceInterface.DriveRates[]'. ret = {0,1,2,3} . How should I do this instead. Again, I am trying to convert an

VS2008 to VS2010 project conversion

蹲街弑〆低调 提交于 2019-12-07 00:07:58
问题 I have a component project build in VS2008 and targeting the .NET Framework 3.5. I recently downloaded the VS2010 Beta 1 to make sure this project would convert over correctly when the time comes to switch to the new IDE. This project contains references to a couple of 3rd party dlls built against version 2.0 of the framework. I changed my project to build against the 4.0 version of the framework but when I try to build the project I get a ton of errors that looks like the compiler can't

Cleanly interrupt HttpListener's BeginGetContext method

删除回忆录丶 提交于 2019-12-06 23:26:26
问题 I am using a HttpListener and using BeginGetContext to get my context object. I want to cleanly shut down my HttpListener but if I attempt to do a Close on the listener I get a exception and it causes my program to exit. using System; using System.Net; namespace Sandbox_Console { class Program { public static void Main() { if (!HttpListener.IsSupported) { Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class."); return; } // Create a listener. HttpListener