c#-5.0

Specific working example needed using IProgress interface described by Albahari

早过忘川 提交于 2019-12-12 00:45:01
问题 I am a neophyte at C# threading. I am trying to get my head around how to make 100K web requests, with some degree of parallelism , and report progress real-time to the GUI: urls processed so far: ###### total moved so far: ###### timed out so far: ####3 I am reading pages 596ff in C# 5.0 in a Nutshell by the Albahari brothers, the section on Progress Reporting. At this point, I don't see how in the Progress instance these counters would be incremented in a thread-safe manner, and exactly how

Cannot apply Await and Async properly in C#5.0

a 夏天 提交于 2019-12-11 23:21:11
问题 I have the below program that will move files from one directory to other. In sysnchronous way, it works fine.But I want to do it in the asynchronous way. Thanks 回答1: The error says it all: you can't await something that is void . You can only await Task s and things that look similar to Task s (e.g. YieldAwaitable, that's returned by Task.Yield()). But you most certainly can't await void . There doesn't seem to be a way to asynchronously move a file in .Net 4.5. The best you can do is to

Get field from dynamically/programatically named column name and Sum with EF

自古美人都是妖i 提交于 2019-12-11 19:55:02
问题 Today I done it here: Get field from dynamically/programatically named column name with Entity Framework I referrenced it because this question is very similiar to it. I would like to get all int values from specific column and sum them and return the value... I how can I do it? For Example: string column_name = "Col1"; int meterID = 6; As old method: "SELECT SUM( column_name ) FROM table_name Where MeterID = meterID ;" 回答1: If you have a class public class TableName { public int MeterId {

Have Web API controller wait for IAsyncResult before completing?

一笑奈何 提交于 2019-12-11 17:34:00
问题 I have a Web API controller. It calls a method that returns an IAsyncResult. When I call the controller, I get the error An asynchronous module or handler completed while an asynchronous operation was still pending. How do I get the controller to wait for the asyncresult? I was planning to use await, but I may just not have figured out the syntax for this use case. I haven't found an existing answer on SO. I'm using c# 4.5 [HttpGet] [Route("GetGridDataAsync")] public string GetGridDataAsync()

Referencing App.config file through a .NET class library DLL in ColdFusion 9

我们两清 提交于 2019-12-11 10:24:03
问题 I'm currently developing DLLs in .NET that use Entity Framework to access our database. It is my understanding that DLLs do not have ties with the same App.config files as exe applications do. Through a good amount of research, I have learned that DLLs do not contain App.config and are best left agnostic(config) so the program using the DLL can determine the config. I'm receiving this error and am sure that the connection string is defined in my app.config: System.InvalidOperationException:

Await method that returns Task - spins forever?

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:27:29
问题 I have the following NUnit test class: [TestFixture] public class Tests { async Task<string> GetMessageAsync() { return "Hello from GetMessageAsync!"; } Task<string> GetMessageTask() { return new Task<string>(() => "Hello from GetMessageTask!"); } [Test] public async void AwaitAsyncMethod() { Assert.AreEqual("Hello from GetMessageAsync!", await GetMessageAsync()); } [Test] public async void AwaitTaskMethod() { Assert.AreEqual("Hello from GetMessageTask!", await GetMessageTask()); } } The

Why does an async function without an await result in a compiler warning?

这一生的挚爱 提交于 2019-12-11 03:32:51
问题 Can anyone explain why async functions in c# 5 are required to have at least 1 await? I can't find a clear reason/explaination. By required, I mean that the compiler warns when an async function doesn't have any await calls inside of it, but doesn't throw a compile error. From this answer: Similarly, a method marked as async must have at least one await. On an await, the runtime will save the current thread's state and call stack, make the asynchronous call, and unwind back to the runtime's

will Task.Run() make any difference in performance?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:55:08
问题 I have a method which calls database as shown below: BL Method to call DAO method: public async Task<List<Classes>> GetClassesAndAddRules(string classId) { var classData = await Task.Run( () => _daoClass.GetClasses(classId)); //logic for adding rule //.................................. } DatabaseCall in DAO: //*below method takes 1 second approx to return* public List<Classes> GetClasses(string id) { var retVal = new List<Classes>(); using (var context = new test_db_context()) { var rows =

“Iterating” over an async method

谁都会走 提交于 2019-12-11 02:49:33
问题 A few related questions about the async CTP: I can iterate over an Iterator Block (an IEnumerable<T> yield-returning T ) using GetEnumerator() and then enumerator methods MoveNext() , and Current() . What is the analog for async methods? How can a non- async calling method to receive and process any await ed items and then ContinueWith() ? Can you provide a short example? I'm just not seeing it. Also, in this following example async method, MyAwaitable has a GetAwaiter() method. If GetAwaiter

Async generic delegate in C# 5.0

徘徊边缘 提交于 2019-12-11 02:26:14
问题 With Iterators, the following generic delegate is possible: public delegate IEnumerable<TOut> MyDelegate<TIn>(TIn param1); With the new async/await in C# 5.0 CTP, I expect to be able to create the analogous delegate as follows: public delegate async TOut MyDelegate<TIn>(TIn param1); I can't find the C# 5.0 spec or any help in this regard. Anyone know how this can be written or if it can't be written and why? Thanks! 回答1: async is an implementation detail, not an interface specification. An