.net-4.5

How to create folder with trailing dot (.) in .NET/C#?

末鹿安然 提交于 2019-12-07 22:37:58
问题 I need to create folders with trailing dots (.) using C#. Here is my code: System.IO.Directory.CreateDirectory("d:\\MyCorp Inc."); But the folder is created without the final dot. Is there a solution? I am using .NET Framework 4.5/C#. My file system is NTFS, on Windows 8. 回答1: Try: using System.Runtime.InteropServices; class Program { [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes); private static void

Linq's Enumerable.Count method checks for ICollection<> but not for IReadOnlyCollection<>

ぐ巨炮叔叔 提交于 2019-12-07 18:52:00
问题 Background: Linq-To-Objects has the extension method Count() (the overload not taking a predicate). Of course sometimes when a method requires only an IEnumerable<out T> (to do Linq), we will really pass a "richer" object to it, such as an ICollection<T> . In that situation it would be wasteful to actually iterate through the entire collection (i.e. get the enumerator and "move next" a whole bunch of times) to determine the count, for there is a property ICollection<T>.Count for this purpose.

In parallel call, limit executions per second

两盒软妹~` 提交于 2019-12-07 17:23:14
问题 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? 回答1: 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

Howto: Parallel.Foreach executes many processes, after each process run a new process (but one at a time)? [closed]

China☆狼群 提交于 2019-12-07 13:46:21
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm sure someone knows this and I will be very thankful for the answer. I don't know much about delegates and asynch and the like - so please give me a general example of how I could implement. I have a workflow

.Net 4.5 wpf printing issue, paper size is always NorthAmericaLetter

会有一股神秘感。 提交于 2019-12-07 13:13:40
问题 I have an issue with printing in WPF. In .Net 4.5 it always prints with paper size NorthAmericaLetter. In .Net Framework 3.5 it prints on the correct paper size, which I defined in Code. I tried it in the same Solution, with the same Code and just changed the Target Framework. My question is, am I missing something in the PrintTicket configuration or how can I set the paper size in .Net 4.5 correctly? var visual = new DrawingVisual(); using (var context = visual.RenderOpen()) { context

How do you configure protobuf-net's RuntimeModel.Default to support serializing/deserializing a SessionSecurityToken?

前提是你 提交于 2019-12-07 12:41:56
问题 BinaryFormatter is able to handle serialization simply: private byte[] TokenToBytes(SessionSecurityToken token) { if (token == null) { return null; } using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, token); return memoryStream.ToArray(); } } When I tried replacing BinaryFormatter with protobuf-net: using (var memoryStream = new MemoryStream()) { Serializer.Serialize(memoryStream, token); return memoryStream

How to async stream a file from database to webclient without buffering

ε祈祈猫儿з 提交于 2019-12-07 12:06:49
问题 I'm trying to async stream a file from sql server out to a web client using .net 4.5 and web api. I'm using SqlDataReader.GetStream() to get a stream from the db. However, I'm not sure how to wire in the disposal/closing of the db connection when webapi is finished reading from the stream. Any samples out there? 回答1: You can write a wrapping stream that reads from the underlying stream until it is depleted, and then disposes of all associated resources (like the SqlConnection). I'm not a

Serialization Exception in .NET 4.5

杀马特。学长 韩版系。学妹 提交于 2019-12-07 11:05:10
问题 I'm getting this stack trace when I call: XslCompiledTransform.Transform(XmlDocument.DocumentElement.CreateNavigator(), null, StringWriter) System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Runtime.Serialization.SerializationException: Type is not resolved for member --MyProject stuff at System.AppDomain.GetHostEvidence(Type type) at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType) at System.Security

how to create a .rules file in workflow foundation 4.5 (VS2012)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 10:51:42
问题 I am new to workflow foundation and I am using workflow foundation 4.5 (VS2012 RC). I want to build a workflow where i can add/remove rules on the run time. So i was thinking of using a set of rules on a separate .rules file and change this as and when I need it. However, i can't find this on VS2012. Is there any way that I can uses dynamic rules in workflow foundation 4.5? 回答1: This code block should allow you to load and execute your rules dynamically. You can see the rest of this post,

How to Interop with Windows Runtime in .NET 4.5

和自甴很熟 提交于 2019-12-07 08:49:17
问题 I see this namespace: System.Runtime.InteropServices.WindowsRuntime Which provides interop between .NET and WindowsRuntime. For instance, you can invoke a method in WindowsRuntime when you create a Metro application, as Metro uses WindowsRuntime, like Windows.System.UserProfile.UserInformation But when you create a normal .NET console application or WPF application, you can no longer directly reach WindowsRuntime namespaces such as Windows.System I wonder if it were possible to invoke