Tag: asynchronous

什么是AsyncCallback?

AsyncCallback有什么用,我们为什么要用它?

ASP.NET服务器不会asynchronous处理页面

我有一个页面的button,我想通过点击buttonasynchronous加载2数据网格与数据。 这是页面的代码,我使用jQuery来调用其他2页,将产生我的HTML。 <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Test" %> <asp:Content ID="Content2" ContentPlaceHolderID="cphCenter" Runat="Server"> <style type="text/css"> #wait { position:absolute; top:0px; right:10px; width:200px; z-index:1000; vertical-align:middle; text-align:center; background: #febf00; display:none; } </style> <script src='<%= ResolveUrl("../../../../Scripts/jquery-1.4.1.js") %>' type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#wait') .ajaxStart(function () { $(this).show(); }) .ajaxStop(function () { $(this).hide(); }); $('input:button').live('click', loadData); }); […]

我知道callback函数asynchronous运行,但为什么?

哪一部分语法提供了这个函数应该在其他线程中运行并且是非阻塞的信息? 让我们考虑node.js中的简单asynchronousI / O var fs = require('fs'); var path = process.argv[2]; fs.readFile(path, 'utf8', function(err,data) { var lines = data.split('\n'); console.log(lines.length-1); }); 究竟是什么使得它发生在后台? 任何人都可以解释它精确或粘贴到一些好的资源的链接? 我看到的地方有很多关于callback是什么的信息,但没有人解释为什么它实际上是这样的。 这不是关于node.js的具体问题,而是关于每种编程语言中callback的一般概念。 编辑: 可能我提供的例子在这里不是最好的。 所以我们不要考虑这个node.js代码片段。 我一般问 – 什么使程序在遇到callback函数时继续执行的技巧。 callback概念是一个非阻塞的语法是什么? 提前致谢!

如何在Angular 2中创build一个简单的JSONPasynchronous请求?

我试图将下面的Angular 1代码转换成Angular 2: $http.jsonp('https://accounts.google.com/logout'); 它需要是一个JSONP请求来跳过CORS策略问题。

以Layman的术语理解asynchronous代码

我理解asynchronous的基本原理:事情不会按顺序执行。 据我所知,有一些非常强大的东西。 但是对于我的生活,我无法将自己的头围绕在代码上。 让我们来看看我写的asynchronousNode.JS代码…但是并没有真正得到。 function newuser(response, postData) { console.log("Request handler 'newuser' was called."); var body = '<html>' + '<head>' + '<meta http-equiv="Content-Type" content="text/html; ' + 'charset=UTF-8" />' + '</head>' + '<body>' + '<form action=" /thanks" method="post">' + '<h1> First Name </h1>' + '<textarea name="text" rows="1" cols="20"></textarea>' + '<h1> Last Name </h1>' + '<textarea name="text" rows="1" […]

如何从Google Maps JavaScript地理编码器callback中返回variables?

我正在使用谷歌地图API,每当我从codeLatLng函数返回的variables初始化函数它声称未定义。 如果我从codeLatLng打印variables,它显示正常。 var geocoder; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(40.730885,-73.997383); var addr = codeLatLng(); document.write(addr); } function codeLatLng() { var latlng = new google.maps.LatLng(40.730885,-73.997383); if (geocoder) { geocoder.geocode({'latLng': latlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { return results[1].formatted_address; } else { alert("No results found"); } […]

最简单的方法来等待一些asynchronous任务完成,在Javascript中?

我想删除一些MongoDB集合,但这是一个asynchronous任务。 代码将是: var mongoose = require('mongoose'); mongoose.connect('mongo://localhost/xxx'); var conn = mongoose.connection; ['aaa','bbb','ccc'].forEach(function(name){ conn.collection(name).drop(function(err) { console.log('dropped'); }); }); console.log('all dropped'); 控制台显示: all dropped dropped dropped dropped 什么是最简单的方法来确保all dropped将被打印所有集合已被删除后? 任何第三方都可以用来简化代码。

正确使用Task.Run时,只是asynchronous等待

我想问你关于何时使用Task.Run的正确架构的Task.Run 。 我在WPF .NET 4.5应用程序(Caliburn Micro框架)中遇到了laggy UI。 基本上我在做(非常简化的代码片段): public class PageViewModel : IHandle<SomeMessage> { … public async void Handle(SomeMessage message) { ShowLoadingAnimation(); // Makes UI very laggy, but still not dead await this.contentLoader.LoadContentAsync(); HideLoadingAnimation(); } } public class ContentLoader { public async Task LoadContentAsync() { await DoCpuBoundWorkAsync(); await DoIoBoundWorkAsync(); await DoCpuBoundWorkAsync(); // I am not […]

Angular2和Observable:不能绑定到'ngModel',因为它不是'select'的已知属性

编辑:更新Plunkr: http ://plnkr.co/edit/fQ7P9KPjMxb5NAhccYIq?p=preview 这部分工作: <div *ngFor="let entry of entries | async"> Label: {{ entry.label }}<br> Value: {{ entry.value }} </div> 但是我在select框有问题,错误信息是: 无法绑定到'ngModel',因为它不是'select'的已知属性 整个组件: //our root app component import {Component} from '@angular/core'; import {NgFor} from '@angular/common'; import {HTTP_PROVIDERS, Http} from '@angular/http'; import 'rxjs/Rx'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', providers: [HTTP_PROVIDERS], template: ` <select [(ngModel)]="selectValue" […]

提升asio async_write:如何不交错async_write调用?

这是我的实现: 客户端A向客户端B发送消息 服务器通过async_read处理消息来async_read正确的数据量,并等待来自客户端A的新数据(按顺序不阻塞客户端A) 之后,服务器将处理这些信息(可能做一个mysql查询),然后用async_write发送消息给客户端B. 问题是,如果客户端A发送消息的速度非常快,那么在调用前一个async_write处理程序之前, async_writes会交错。 有一个简单的方法来避免这个问题? 编辑1:如果一个客户端C发送一个消息到客户端B刚刚客户端后,同样的问题应该出现… 编辑2:这将工作? 因为它似乎阻止,我不知道在哪里… namespace structure { class User { public: User(boost::asio::io_service& io_service, boost::asio::ssl::context& context) : m_socket(io_service, context), m_strand(io_service), is_writing(false) {} ssl_socket& getSocket() { return m_socket; } boost::asio::strand getStrand() { return m_strand; } void push(std::string str) { m_strand.post(boost::bind(&structure::User::strand_push, this, str)); } void strand_push(std::string str) { std::cout << "pushing: " […]