c#-5.0

RESTful authentication. Client-side, stateless unauthentication

≯℡__Kan透↙ 提交于 2019-12-04 07:49:28
I'm implementing a set of RESTful services for some developments and one of these is an authentication service . This authentication service authenticates two kinds of identities: Applications . AppKey-based authentication so clients must register for a key in order to access to the rest of the services . Users . Well-known credentials (user+password)-based user authentication so humans and machines can work with these RESTful services through client applications. These RESTful services are stateless . When a client application authenticates against the authentication service , or when a human

C#5 AsyncCtp BadImageFormatException

匆匆过客 提交于 2019-12-04 07:43:07
Please help me with this one, I've been writing a console applicaiton using the AsyncCtpLibrary and the C#5 ctp compiler. First time I got to actually running a code which awaits, I got this: System.BadImageFormatException was unhandled Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Source=AsyncCtpLibrary StackTrace: Server stack trace: at [...].<Execute>d__1c.MoveNext() at [...].Execute() at [...].<Move>d__1d.MoveNext() in[..]:line 266 Exception rethrown at [0]: at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.

Default TaskCreationOptions in Task.Run

孤街浪徒 提交于 2019-12-04 05:08:18
Why the default value for CreationOptions of a Task created using Task.Run is DenyChildAttach rather than None ? Has it anything to do with making work with the new async and await in C# 5.0 simpler (by preventing you from escaping current scheduler of current context I guess)? Stephen Toub explains this well in his blog post on the subject . Parent and child tasks are somewhat common when using Task s in a parallel fashion. Note that when a parent Task has a child, the parent's completion semantics change subtly. Parent/child tasks are almost never used when using Task s in an async fashion.

Using C# 5 async feature in Linqpad

≯℡__Kan透↙ 提交于 2019-12-04 02:17:32
Is it possible to use C# 5 async features in Linqpad snippets? Does anyone know of any hack/beta which allows you to do it? Joe Albahari Installing the async CTP should be enough - async code should compile in LINQPad (although the Intellisense will show red squigglies). I'll look at dealing to the red squigglies in the next beta :) You will have to add a reference to asyncctplibrary.dll , as in VS. Update: the red squigglies and autocompletion has been dealt to in the latest beta . 来源: https://stackoverflow.com/questions/5893882/using-c-sharp-5-async-feature-in-linqpad

Can/should Task<TResult> be wrapped in a C# 5.0 awaitable which is covariant in TResult?

孤街醉人 提交于 2019-12-04 01:41:52
I'm really enjoying working with C# 5.0 asynchronous programming. However, there are a few places where updating old code to be consistent with the TAP model is causing problems for me. Here's one of them - I'm not sure exactly why Task<TResult> is not covariant in TResult, but it's causing problems for me when trying to update a covariant interface to move from a synchronous to an asychronous pattern: Old code: public interface IInitializable<out T> // ** out generic modifier ** { /// <summary> /// Boolean to indicate if class is ready /// </summary> bool IsInitialized { get; } /// <summary>

C# 5 and async timers

元气小坏坏 提交于 2019-12-04 00:17:48
Is there a new Timer API somewhere that allows me to do this? await timer.wait(500); Basically, to sleep for X ms and then resume execution of the rest of a function Try use await Task.Delay(500); I have a helper that I really like, just to add a bit of readability: public static Task Seconds(this int seconds) { return Task.Delay(new TimeSpan(0,0,seconds)); } This allows me to use something like await 5.Seconds(); You could easily make similar extension methods for milliseconds, minutes, hours, or whatever. 来源: https://stackoverflow.com/questions/9746555/c-sharp-5-and-async-timers

Why compiler does not allow using await inside catch block

白昼怎懂夜的黑 提交于 2019-12-03 23:54:01
Let say I have an async method: public async Task Do() { await Task.Delay(1000); } Another method is trying to call Do method inside catch block public async Task DoMore() { try { } catch (Exception) { await Do(); //compiled error. } } But this way, the compiler does not allow using await inside catch , is there any reason behind the scene why we could not use it that way? Update This will be supported in C# 6. It turned out that it wasn't fundamentally impossible, and the team worked out how to do so without going mad in the implementation :) Original answer I strongly suspect it's the same

Sending mail with task parallel library throws error

ε祈祈猫儿з 提交于 2019-12-03 22:08:30
问题 CODE:- List<Task> tasks = new List<Task>(); foreach (var item in arr)//arr contains 1000+ mailids { tasks.Add(Task.Factory.StartNew(() => { using (MailMessage msg = new MailMessage()) { msg=getmsg();//p-shadow code no erorr here SmtpClient smtp = new SmtpClient(); smtp.Host = smtpServer; smtp.Port = smtpPort; smtp.EnableSsl = isSmtpSsl != 0 ? true : false; smtp.Credentials = new NetworkCredential(smtpUName,smtpPass); smtp.Timeout = int.MaxValue; smtp.Send(msg);//---throws error.... //sql code

How does C# 5 async return to main thread?

陌路散爱 提交于 2019-12-03 17:37:19
I was watching a vid about Async CTP and saw that if you call await from e.g. main thread , then the execution will continue from main thread when the work is completed. e.g //called from main thread var result = await SomeAsyncWork(); //this will execute in main thread also console.writeline(result) I had the naive impression that there would be a normal call back going on which would be executed on a worker thread. At some level that must be what is going on since you can wrap normal async methods in a Task of T with Task.FromAsync but normal async methods will run in worker threads, so how

How do you send multiple parameters in a Url.Action?

有些话、适合烂在心里 提交于 2019-12-03 16:14:30
问题 How do you send multiple parameters in an Url.Action ? I have a controller with an action, and I want 2 parameters, but the 2nd parameter is not being received. My code is: @Url.Action("Products", "Jquery", new { categoryid = 1, Productid = 2}) Publc Action Jquery(int categoryid ,int Productid) { } but I only receive categoryid , every time Productid is null. Please suggest to me what to do? 回答1: try it like this. @Url.Action("Jquery", "Products", new { @categoryid = 1, @Productid = 2})