.net-4.0

C# Lazy Initialization && Race-to-initialize?

送分小仙女□ 提交于 2019-12-07 07:41:48
问题 After reading about LazyInitializer that it's : It offers another mode of initialization that has multiple threads race to initialize. here is a sample : Expensive _expensive; public Expensive Expensive { get // Implement double-checked locking { LazyInitializer.EnsureInitialized (ref _expensive,() => new Expensive()); return _expensive; } } Question #1 looking at : why #A says its implements double-checking locking ? it is just a get proeprty ? Question #2 Does #B (lambda expression) is

Writing Group By on Anonymous Types

我只是一个虾纸丫 提交于 2019-12-07 07:14:52
问题 I am writting a group by clause on two tables which are joined and being accessed via Entity Data Model. I am not able to iterate over the anonymous type, can somebody help me out. public string GetProductNameByProductId(int productId) { string prodName=string.Empty; using (VODConnection vodObjectContext = new VODConnection()) { var products = from bp in vodObjectContext.BFProducts join bpf in vodObjectContext.BFProductMasters on bp.ProductMasterId equals bpf.ProductMasterId where bp

Derived method stronger than override in c#?

房东的猫 提交于 2019-12-07 07:07:22
问题 ( again annoying question... ) after asking this before - ( which is partly related to my question) - i got an answer : See §7.6.5.1 of the C# 4 spec: The set of candidate methods is reduced to contain only methods from the most derived types: For each method C.F in the set, where C is the type in which the method F is declared, all methods declared in a base type of C are removed from the set. ok. i have this code : // .Dump() is like a WriteLine command... public class Base { public void

How can I run a WCF service constructor once for all clients when it's InstanceContextMode is set to PerSession?

旧街凉风 提交于 2019-12-07 05:46:26
How can I run the code in the constructor of a WCF Service only once when the ServiceBehaviorAttribute.InstanceContextMode is set to PerSession ? [ServiceBehavior( InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)] public class SomeService : ISomeService { public SomeService() { this.RunThisOnceForAllClients(); } private void RunThisOnceForAllClients() { } } Or, how can I make a method run automatically once the WCF Service is running but it will only run once for all client calls ? Please help. Thanks in advance. I deploy my WCF Service using a

Why doesn't TextRenderer.MeasureText work properly?

懵懂的女人 提交于 2019-12-07 05:37:16
问题 I want to measure the height of the text given a certain width of available canvas. The text that I pass in is really long and I know will wrap. To that end, I call the following: using System.Windows.Forms; ... string text = "Really really long text that is sure to wrap..."; Font font = new Font("Arial", 14); Size canvas = new Size(1100, 850); Size size = TextRenderer.MeasureText(text, font, canvas); No matter what I pass in for canvas, it always returns 14 for size.Height . Am I missing

Using MSpec runner in Visual Studio 2010 and .NET 4

Deadly 提交于 2019-12-07 04:58:53
问题 I'm a big fan of MSpec so naturally I wanted to use is right away with VS2010 as well. I have the MSpec runner defined as an external tool in Visual Studio to be able to have it always visible as a toolbar item. Anyway, whenever I try to use the MSpec runner (mspec.exe) with a .NET 4.0 solution I get the following error: Could not load file or assembly 'file:///C:\Users\[SOMEUSER]\[SOME_FOLDERS]\bin\Debug\[PROJECT].Specs.dll' or one of its dependencies. This assembly is built by a runtime

Are there better (easier) ways to get a specific domain's SID?

一曲冷凌霜 提交于 2019-12-07 04:25:00
问题 I've been assigned to modify a WinForms application to basically check that the logged on user belongs to a specific domain. This is what I've come up with so far: byte[] domainSid; var directoryContext = new DirectoryContext(DirectoryContextType.Domain, "domain.se"); using (var domain = Domain.GetDomain(directoryContext)) using (var directoryEntry = domain.GetDirectoryEntry()) domainSid = (byte[])directoryEntry.Properties["objectSid"].Value; var sid = new SecurityIdentifier(domainSid, 0);

Change Windows Wallpaper using .NET 4.0?

我们两清 提交于 2019-12-07 04:21:57
问题 Is there a way to change the Windows wallpaper using some new feature in .NET 4? 回答1: You can use SystemParametersInfo to set the desktop wallpaper. This should work consistently on all versions of windows that your app can run on, however will require some interop. The following interop declarations are what you need public const int SPI_SETDESKWALLPAPER = 20; public const int SPIF_UPDATEINIFILE = 1; public const int SPIF_SENDCHANGE = 2; [DllImport("user32.dll", CharSet = CharSet.Auto,

Can application built with .NET 4.5 run on .NET 4.0?

时间秒杀一切 提交于 2019-12-07 03:58:16
问题 My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed. This is all good until I added some extension methods and reflection. Then when I ran this .NET 4.5 program on the 4.0 machine, it failed with "System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly mscorlib". The famous ExtensionAttribute program that has been documented well here. Another

Lambda with nested classes

杀马特。学长 韩版系。学妹 提交于 2019-12-07 03:01:09
问题 I have posted this question a while ago but got a partial answer to my issue, so I thought I post more explanation hoping to get a more accurate answer. I have 2 classes: public class Employee { public string Name { get; set; } public List<Cars> Cars { get; set; } } public class Car { public int CarID { get; set; } public CarTypes CarType { get; set; } public enum CarTypes { Van, SmallCar } } I'm trying to get only All employees that have vans allocated to ignoring those with SmallCars using