async

grails async bootstrap

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to use a service asynchronously in the grails bootstrap class? I am trying to do the following in grails-2.0.4 and the grails-executor-plugin, but only the first log message appears: class BootStrap { def myService def init = { servletContext -> log.info("Bootstrapping") runAsync { log.info("Doing myService async ") myService.doSomething() } } There is no error message, just no output from the second log statement. Thanks a lot in advance! 回答1: Remove runAsync closure - it is not the right place for it. You can use closures

How to cancel an async WCF call?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been trying some time to find out how to implement WCF call cancellation based on the new .NET 4.5 CancellationToken mechanism. All the samples I found are not WCF based, and do not cross the service boundary. My service : [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class MyService : IMyService { public void LongOperation() { // do stuff that takes ages... // please cancel me! } } My Client (Desktop App): Using an auto generated proxy : private async void DoLongRunningTaskAsync() { var asyncTask =

TaskScheduler with async sequential Tasks C#

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am executing some .py scripts async. One Script takes about 30 seconds to be executed. It could happen that two or even more Scripts are being selected in a timespan of two or three seconds. The Goal is to have a Scheduler which collects all the tasks and executes them one after the other. A FIFO functionality should be included. I 've tried the following Code just to try the functionality of the queuedTaskScheduler, but even that doesn't work. QueuedTaskScheduler queueScheduler; private TaskScheduler ts_priority1; int pos = 0; public

Python asyncio.semaphore in async-await function

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to teach myself Python's async functionality. To do so I have built an async web scraper. I would like to limit the total number of connections I have open at once to be a good citizen on servers. I know that semaphore's are a good solution, and the asyncio library has a semaphore class built in. My issue is that Python complains when using yield from in an async function as you are combining yield and await syntax. Below is the exact syntax I am using... import asyncio import aiohttp sema = asyncio.BoundedSemaphore(5) async def

$.ajax( { async : false } ) request is still firing asynchronously?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got a little problem here guys. I'm trying to implement the following scenario: A user opens the home page and sees a list of other users and clicks to add one to his friend list. I issue an Ajax request to a server resource to validate if the user is logged in, if so, I issue another ajax request to another server resource to actually add it to the user's friend list. Sounds simple? Here's what I've done: I created a function isLoggedIn that will issue the first request to the server in order to determine if the user is logged in. I issue

Request.Content.ReadAsMultipartAsync never returns

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an API for a system written using the ASP.NET Web Api and am trying to extend it to allow images to be uploaded. I have done some googling and found how the recommended way to accept files using MultpartMemoryStreamProvider and some async methods but my await on the ReadAsMultipartAsync never returns. Here is the code: [HttpPost] public async Task LowResImage(int id) { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var provider = new

Async Implementation of IValueConverter

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If an async Method which I want to trigger inside a IValueConverter. Is there a better Wait then forcing it to be synchronous by calling the result Property? public async Task Convert(object value, Type targetType, object parameter, string language) { StorageFile file = value as StorageFile; if (file != null) { var image = ImageEx.ImageFromFile(file).Result; return image; } else { throw new InvalidOperationException("invalid parameter"); } } 回答1: You probably don't want to call Task.Result , for a couple of reasons. Firstly, as I explain in

MVC Async error - The asynchronous action method 'Complete' cannot be executed synchronously

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using MVC4 with VS 2010. I have an async action that I am trying to get working. My controller inherits from AsyncController and I have the ~Async and ~Completed methods. I am able to execute my async action correctly in a sample test project. But when I run it as part of my core web app it get this exception [InvalidOperationException: The asynchronous action method 'Complete' cannot be executed synchronously.] System.Web.Mvc.Async.AsyncActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters)

ASP.NET async/await part 2

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a variation of the benefits-of-async/await-on-ASP.NET from this question . My understanding is that asynchrony is not the same thing as parallelism. So, on a web server, I wonder about how much benefit async/await brings to ASP.NET pages. Isn't IIS+ASP.NET already really good at allocating threads for requests, and if onen page is busy waiting for a resource the server will just switch to processing another request that has work to do? There are a limited number of threads in the pool for ASP.NET to use - does async use them any more

MongoDB查询转对象时出错 Element '_id' does not match any field or property of class

左心房为你撑大大i 提交于 2019-12-03 02:23:49
参考:https://www.cnblogs.com/94cool/p/6230202.html 解决方法: 1、在实体类加:[BsonIgnoreExtraElements] 2、或者定义public ObjectId _id { get; set; } 例子: [BsonIgnoreExtraElements] public class BaseData { // public ObjectId _id { get; set; } public string cNo { get; set; } public string customer { get; set; } public long batchNo { get; set; } public DateTime mDate { get; set; } public string mUser { get; set; } } 顺便保存下数据库帮助类 public class MongoDBHelper { #region 构造函数(初始化集合,子类需重写集合名) /// <summary> /// 集合 /// </summary> public string _collName { get; set; } public MongoDBHelper(string collName) { this._collName =