c#-5.0

JQuery example for calling SignalR Async Task

时光怂恿深爱的人放手 提交于 2019-12-13 07:37:28
问题 Does anyone have a working example of a JQuery based client calling an async task based method on a SignalR Hub? See the code below from the SignalR Doco for an example of a server side async task. public Task<int> AsyncWork() { return Task.Factory.StartNew(() => { // Don't do this in the real world Thread.Sleep(500); return 10; }); } 回答1: Here is an example * at server side: * public void AsyncWork() { // start working in a new thread var task = Task.Factory.StartNew(() => dosomething());

making database call asynchronous in EF

末鹿安然 提交于 2019-12-13 06:13:24
问题 I am using EF 5.0 and have a question on making the Database calls asynchronous. To begin with below is the autogenerated method call in contextModel>.context.cs public virtual ObjectResult<InstructorsComplex> GetInstructors(string nm, string cd, string grp_cd) { var nmParameter = nm != null ? new ObjectParameter("nm", nm) : new ObjectParameter("nm", typeof(string)); var cdParameter = cd != null ? new ObjectParameter("cd", cd) : new ObjectParameter("cd", typeof(string)); var grp_cdParameter =

Why does XmlReader.ReadInnerXmlAsync hang when reading <ns:element>?

一世执手 提交于 2019-12-13 04:38:30
问题 I encounter strange behavior of the XmlReader.ReadInnerXmlAsync() method. While the following code works... using (XmlReader r = XmlReader.Create(stream, new XmlReaderSettings() { Async = true })) { while (await r.ReadAsync()) { switch (r.NodeType) { case XmlNodeType.Element: if (r.Name.Equals("c")) { string x = await r.ReadInnerXmlAsync(); OnReceive("[ " + x + " ]"); } break; } } } ...and the whole element <c></c> from the following XML is read as string. <?xml version='1.0' encoding='UTF-8'

Is it possible to implement the Yin-Yang puzzle in C# 5.0 using async?

隐身守侯 提交于 2019-12-13 00:36:12
问题 The puzzle, implemented in Scheme, is as follows: (let* ((yin ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c)))) (yang ((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c))))) (yin yang)) The goal of the puzzle is to work out and understand the output of this code. I'm wondering if it's possible to implement code with the same semantics using C# 5.0's new async CPS features. The part that I'm having trouble grasping, is that the puzzle

Calling an async method with c#5.0

随声附和 提交于 2019-12-12 17:44:50
问题 I do some tests with the new asynchronous pattern of C# 5.0 (async/await) I have a problem with understanding how the asynchronous methods are called. Considering this code : private async Task<string> DownloadAsync() { progress.ProgressChanged += (s, e) => { progressBar1.Value = e.value; }; return await DownloadSomething(myurl, progress); } private async void CallDownloadAsync() { string text = await DownloadAsync(); progressBar1.Value = 0; label1.Text = "Done!"; } private void button4_Click

Using C# 5 async to wait for something that executes over a number of game frames

萝らか妹 提交于 2019-12-12 16:41:41
问题 My son is writing a simple RPG game that has a number of non-player characters (aka NPC's). Each NPC has an associated "script" that controls its behaviour. We were going to use a mini custom script language to write these behaviours but I'm now wondering if this would be better done in C#5/Async. Taking a really simple example, suppose one of the NPC's just walks between two points I'm thinking it would be nice to write something like this: while (true) { await WalkTo(100,100); await WalkTo

C# async awaitable clarification?

人走茶凉 提交于 2019-12-12 15:16:01
问题 I've read here that : Await examines that awaitable to see if it has already completed; if the awaitable has already completed, then the method just continues running (synchronously, just like a regular method). What ? Of course it won't be completed because it hasn't even started ! example : public async Task DoSomethingAsync() { await DoSomething(); } Here await examines the awaitable to see if it has already completed (according to the article) , but it (DoSomething) haven't event started

Page.AsyncTimeout - endless timeout?

元气小坏坏 提交于 2019-12-12 14:37:11
问题 I saw an example of forever iframe implementation ( comet simulation ) , so I decided to test it but with the addition of asynchronous approach , so that there will be no blocking. Pretty simple : I have a page ( index.html ) with hidden iframe which has SRC of AdminPush.aspx : /*1*/ protected void Page_Load(object sender, EventArgs e) /*2*/ { /*3*/ UpdateMessage(); /*4*/ } /*5*/ /*6*/ /*7*/ protected void UpdateMessage() /*8*/ { /*9*/ HttpContext.Current.Response.ContentType = "text/html"; /

async / await or Begin / End with TcpListener?

寵の児 提交于 2019-12-12 08:03:58
问题 I've started to build a tcp server which will be able to accept many clients, and receive simultaneously from all of the clients new data. Until now, I used IOCP for tcp servers which was pretty easy and comfortable, but this time I want to use the Async / Await tech. that was released in C# 5.0. The problem is that when I started to write the server using async / await, I figured out that in tcp multiple users server use case, async / await tech. and the regular synchrony methods will work

How can I implement a 1s delay before my progress/cancel dialog is shown?

我与影子孤独终老i 提交于 2019-12-12 02:14:09
问题 I'm trying to construct a progress/cancel form for use within my WinForms application that runs any await-able "operation", while providing the user with some progress information and an opportunity to cancel the operation. Because the form is shown using ShowDialog() , it's a modal form which nicely disables the form underneath - so I don't need to mess around with disabling all the controls on that other form. They way I've implemented it, which I fully expect you to rip to shreds :-), is