.net-4.5

How to use async/await with a library that uses an event-based asynchronous pattern?

≯℡__Kan透↙ 提交于 2019-12-30 10:32:34
问题 I use a library that has an asynchronous method called DoWork(...) that will raise a WorkDone event when the operation completes. I would like to write a method that calls this library, but instead of maintaining the same pattern I would like my method to be async so it can be called with await . In essence, what I am trying to do is: public async Task<Result> SomeMethod() { var result = new Task<Result>(); library.WorkDone += (data) => { result.Result = data; } library.DoWork(); return await

Passing JSON Array from Javascript to Web API Controller method

[亡魂溺海] 提交于 2019-12-30 08:13:03
问题 I was not able to get the JSON array parameters in web api controller method (SaveDetails). Here are my code. JavaScript Code: $.ajax( { url : "api/Test/SaveDetails", type : "POST", data : { "employees": [ { "firstName": "John", "lastName": "Doe" }, { "firstName": "Anna", "lastName": "Smith" }, { "firstName": "Peter", "lastName": "Jones" } ] }, success: function (data) {alert("success");}, error: function () {alert("Error");} }) Controller method [HttpPost] public DataSet SaveDetails(Models

MaxLength Attribute in EF4.3.1

有些话、适合烂在心里 提交于 2019-12-30 06:09:24
问题 The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' exists in both [path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework \.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll' Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder

Can a build server with .NET 4.5 installed successfully deploy a project targeting 4.0 to a server with only .NET 4.0 installed?

余生长醉 提交于 2019-12-30 04:28:26
问题 We've recently installed .NET 4.5 onto our continuous integration build server so that it can support new projects that utilize features of .NET 4.5. This build server is also used to build and deploy older projects, as well, some of which target .NET 4.0. Projects that target .NET 4.0 being built on this server, then deployed to a target server that has only .NET 4.0 installed are now failing with the following error: Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.

What are the differences between using ConfigureAwait(false) and Task.Run?

社会主义新天地 提交于 2019-12-29 10:14:45
问题 I understand that it's recommended to use ConfigureAwait(false) for await s in library code so that subsequent code does not run in the caller's execution context, which could be a UI thread. I also understand that await Task.Run(CpuBoundWork) should be used instead of CpuBoundWork() for the same reason. Example with ConfigureAwait public async Task<HtmlDocument> LoadPage(Uri address) { using (var client = new HttpClient()) using (var httpResponse = await client.GetAsync(address)

App Manifest Ignored

别来无恙 提交于 2019-12-29 09:07:25
问题 I am developing an app in Visual Studio 2013 on Windows 7 x64 that requires administrator privileges but it appears my manifest is being ignored: <?xml version="1.0" encoding="utf-8"?> <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> <trustInfo xmlns="urn

Reference could not be added because of same name

百般思念 提交于 2019-12-29 06:39:26
问题 Since the update to VS 2013 I have the behaviour that I cannot add a reference to 2 projects with the same name. I did the following: Added 3 solution folders A, B and C. Added a project of type class library "Core" to both A and B folder. Added a project of type ConsoleApplication to folder C. The resulting structure looks like this: Solution + A + Core + B + Core + C + ConsoleApp In the project properties of A the following is entered: Assembly name: A.Core Default namespace: A.Core and in

How do I convert this to an async task?

蹲街弑〆低调 提交于 2019-12-28 20:41:44
问题 Given the following code... static void DoSomething(int id) { Thread.Sleep(50); Console.WriteLine(@"DidSomething({0})", id); } I know I can convert this to an async task as follows... static async Task DoSomethingAsync(int id) { await Task.Delay(50); Console.WriteLine(@"DidSomethingAsync({0})", id); } And that by doing so if I am calling multiple times (Task.WhenAll) everything will be faster and more efficient than perhaps using Parallel.Foreach or even calling from within a loop. But for a

How do I convert this to an async task?

微笑、不失礼 提交于 2019-12-28 20:41:35
问题 Given the following code... static void DoSomething(int id) { Thread.Sleep(50); Console.WriteLine(@"DidSomething({0})", id); } I know I can convert this to an async task as follows... static async Task DoSomethingAsync(int id) { await Task.Delay(50); Console.WriteLine(@"DidSomethingAsync({0})", id); } And that by doing so if I am calling multiple times (Task.WhenAll) everything will be faster and more efficient than perhaps using Parallel.Foreach or even calling from within a loop. But for a

Simple claims transformation and caching w/ windows authentication

不打扰是莪最后的温柔 提交于 2019-12-28 08:08:15
问题 For the past few days I've been reading about the windows identity foundation and how it's so good and flexible and built right into .net 4.5. Despite going over dozens of apis, blog posts, how-to's etc. I can't for the life of me get a simple implementation working. I'm using windows authentication only and I can get the principal and view the claims that come with it (which is where every example seems to end). However I want to then transform them into useful claims and cache the results