.net-4.5

Call Async Method from Session_Start

老子叫甜甜 提交于 2019-12-07 08:38:55
问题 How can I call an async method from Session_Start in Global.asax ? Global.asax: protected async Task Session_Start(object sender, EventArgs e) { Session.Timeout = 10; // Do some asynch work await repository.SetStatsInfo(System.DateTime.Now); } async method: public async Task SetStatsInfo(DateTime time) { using (ApplicationDBContext db = new ApplicationDBContext()) { // Do stuff (update visitors counter in db) .. await db.SaveChangesAsync(); } } I can run it all synchronously (define void

Akka.net starting and stopping with no activity

独自空忆成欢 提交于 2019-12-07 08:10:31
I'm trying to send a message from a typesafe akka actor in Scala (2.4.11) to Akka.net actor in C# (1.0.4) I have a weird problem with my .Net actor, it keeps saying started then stopped, but I have no clue whats happening under the hood: A piece of Akka.net log: 2015-11-18 16:23:57.6168|DEBUG|Akka.Remote.Transport.ProtocolStateActor|Started (Akka.Remote.Transport.ProtocolStateActor) 2015-11-18 16:24:27.6578|DEBUG|Akka.Remote.Transport.ProtocolStateActor|Stopped 2015-11-18 16:24:42.6344|DEBUG|Akka.Remote.Transport.AkkaProtocolManager|now supervising akka://converter/system/transports

Metro App FileIO.WriteTextAsync Multiple Threads

扶醉桌前 提交于 2019-12-07 07:59:04
问题 I have a method which is called frequently from multiple threads. It involves writing to disk using await FileIO.WriteTextAsync . This works fine when it is called from a single thread, but once I start doing this in multiple threads, I get this error: The process cannot access the file because it is being used by another process. I know what the error means, but I'm not sure how to work around it. Normally, I would create a lock(object) statement, to ensure that the file is being accessed by

Create delegate from constructor

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 06:58:04
问题 Using reflection, I'm trying to create a delegate from a parameterless constructor like this: Delegate del = GetMethodInfo( () => System.Activator.CreateInstance( type ) ).CreateDelegate( delType ); static MethodInfo GetMethodInfo( Expression<Func<object>> func ) { return ((MethodCallExpression)func.Body).Method; } But I get this exception: "Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type." What will work? Note

Is it possible to cancel a C# Task without a CancellationToken?

孤街浪徒 提交于 2019-12-07 06:38:20
问题 I'm need to cancel an API call that returns a Task, but it doesn't take a CancellationToken as a parameter, and I can't add one. How can I cancel that Task? In this particular case, I'm using Xamarin.Forms with the Geocoder object. IEnumerable<Position> positions = await geo.GetPositionsForAddressAsync(address); That call can sometimes take a very long time. For some of my use cases, the user can just navigate to another screen, and that result of that task is no longer needed. I also worry

Does .NET Framework 4.5 provide SSE4/AVX support?

…衆ロ難τιáo~ 提交于 2019-12-07 06:30:35
问题 I think, I heard about that, but don't know where. upd: I told about JiT 回答1: it seem that it is coming. (I just found out an hour ago) here a few links The JIT finally proposed. JIT and SIMD are getting married. Update to SIMD Support you need the latest version of RyuJIT and Microsoft SIMD-enabled Vector Types (Nuget) 回答2: No, there's no scenario in .NET where you can write machine code yourself. Code generation is entirely up to the just-in-time compiler. It is certainly capable of

Visual Studio “Target framework” missing

柔情痞子 提交于 2019-12-07 06:13:09
问题 I am trying to compile my .NET Standard class library project with .NET Framework 4.5.2. However, as you can see in my screenshot, version 4.5.2 is not shown in the offered list of target frameworks: Furthermore, when I click Install other frameworks... , I am still not given the option of choosing 4.5.2. I am using Visual Studio Community Edition. 回答1: You created the wrong project type. You created a .Net Standard Class Library but you need to create a normal Class Library under Windows

How can I update my API to use the async keyword without using await for all callers

 ̄綄美尐妖づ 提交于 2019-12-07 06:05:34
问题 I am trying to port some TcpClient dependant code to .net 4.5, using StreamSocket and DataReader instead. I have a function named ReadLine() which is used everywhere. By using DataReader in the body ( LoadAsync() ) of this code, my method is forced to be marked with the async keyword. The chain reaction is as follows: Now I have hundreds of places where I have to add async to calling methods and apply await to underlying async method calls. This leads me to my next question... Is there an

Model with collection - Html.ListBoxFor doesn't set selected items

萝らか妹 提交于 2019-12-07 04:48:27
This one is driving me crazy and before I loose my sane please help. Summary of the issue: My model "Thread" has collection of "ForumMessage", each ForumMessage has one Multi select drop down list. All I want to do is set the selected value based on values coming from Database. I have gone thru many threads but wasn't able to find the solution. In case if you are aware of any such question please let me know and I will go thru them. Below are my models public class Thread { public List<ForumMessage> Messages { get; set; } //Master list coming from DB public List<Classifications>

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