handler

boost::asio async handlers invoked without error after cancellation

一个人想着一个人 提交于 2019-12-07 06:09:19
问题 My code uses boost::asio and io_service in a single thread to perform various socket operations. All operations are asynchronous and every handler depends on the boost::system::error_code (particularly boost::asio::error::operation_aborted ) to determine the result of the operation. It's been working perfectly well until I changed the logic to make several concurrent connections and pick the fastest one. That is, when the first async_read_some handler fires, I cancel other sockets (shutdown,

Using HandlerThread and Handler on a separate thread freezes UI thread

一世执手 提交于 2019-12-07 05:46:25
In my project, I want to implement a timer in another thread that counts down the time spent executing a certain method in my application, and do something if it is taking too much time. When executing the MyManager.startCommand() method, the application is freezing and I don't know why since I think I am not doing anything on the UI thread. Is there anything wrong with my code? I had originally asked this question and was not experiencing an app freeze, so I don't think it's because I'm sleeping the thread: Runnable posted in another runnable not executed . public class MyManager{ private

Launching Chrome Packaged Web App from Website

谁说胖子不能爱 提交于 2019-12-07 04:35:58
问题 I have a Chrome Packaged Web app (which is required as it needs to access the Serial Port), and I'd like to be able to launch it from my website (with some data) when I click on a link/button on that website. It'd be even better if it could detect if the user wasn't running chrome or didn't have the web app installed and could direct them to the right place... Are there any examples? It seems like an obvious thing to want to do, but I'm really struggling to find anything... 回答1: To launch an

Handler postDelayed and Thread.sleep()

独自空忆成欢 提交于 2019-12-07 04:20:44
问题 I have a thread.sleep and a handler postDelayed in my code: handler.postDelayed(new Runnable() { @Override public void run() { Log.e(TAG, "I ran"); mIsDisconnect = false; } }, DISCONNECT_DELAY); After the handler code and after the user press the button I have this: while (mIsDisconnect) { try { Thread.sleep(DELAY); } catch (InterruptedException e) { Log.e(TAG, "problem sleeping"); } } If the user wait long enough I can get the "I ran" in my log. But if the user press the button before the

Android Messenger 跨进程通信

馋奶兔 提交于 2019-12-07 02:49:14
如果你需要在不同进程间通信,你可以在Service中使用Messenger来实现进程中通信。 如果使用这种方式,Service中需要定义一个Handler对象(负责对客户端发送过来的Message进行响应)。 Messenger可以共享给client一个IBinder对象,client通过这个IBinder对象向Service发送Message,而前面提到的Handler对象是这一切的基础。 注:使用这种方式进行通信是不支持多线程的。 那就让我们来看看使用这种方式进行通信吧! 注:Service在声明时必须对外开放,即android:exported="true",且本文是通过Intent启动的Service,所以在声明时该Service可以接收特定的Action。 1、在Service中创建一个Handler对象,来处理从client发过来的Message 2、根据创建的Handler对象创建一个Messenger对象 3、使用Messenger的getBinder方法得到一个IBinder对象,并在Service的onBind方法中将其反出去 4、client在onServiceConnected中根据IBinder参数创建一个Messenger对象(可参考Messenger的构造函数) 5

jquery第三天

徘徊边缘 提交于 2019-12-07 02:01:11
jQuery特殊属性操作 val方法: val方法用于设置和获取表单元素的值,例如input、textarea的值 $("#name").val() html方法与text方法: $(“div”).html()----------$(“div”).text() 区别:html方法会识别html标签,text方法会那内容直接当成字符串,并不会识别html标签。 width方法与height方法: 设置或者获取高度 $(“img”).height()--------获取网页的可视区宽高 $(window).width() $(window).height() scrollTop与scrollLeft: 设置或者获取垂直滚动条的位置 $(window).scrollTop()--------$(window).scrollLeft() offset方法与position方法: offset方法获取元素距离document的位置,position方法获取的是元素距离有定位的父元素的位置。 $(selector).offset()=======$(selector).position() jQuery事件机制: jQuery事件发展历程:简单事件绑定>>bind事件绑定>>delegate事件绑定>>on事件绑定 简单事件注册 : click(handler) 单击事件 mouseenter

jqgrid inline edit - Save handler when clicking enter

拟墨画扇 提交于 2019-12-07 01:51:27
Im wondering if there is an event handler for the save method when clicking enter to save the row. I want to use it to hide the row from the grid after being saved. thanks in advance! Both editRow and saveRow inline editing methods has succesfunc and aftersavefunc parameters which you can use. The aftersavefunc has small advantage because it is used in both local and remote holding of the grid data. So the code can be ondblClickRow: function (rowid) { $(this).jqGrid('editRow', rowid, true, null, null, null, {}, function (rowid) { $(this.rows.namedItem(rowid)).hide(); $(this).focus(); // set

I'd like to use multiple services on one transport ( Thrift )

不羁岁月 提交于 2019-12-07 01:11:38
问题 I'd like to create several services, and I want to use them with different identifiers. So I mean : I've got a Users and Projects service . I want to use these at the same time. I mean I can add more 'services' to the "handlermap" on xmlrpc. http://ws.apache.org/xmlrpc/server.html phm.addHandler("Users", Users.class); phm.addHandler("Projects", Projects.class); I would like to do the same in the thrift. Here is a simple example : test.thrift typedef i64 UserId struct Bonk { 1: string message,

[深度分析] Python Web 开发框架 Bottle(作者 @Sunng)

别说谁变了你拦得住时间么 提交于 2019-12-07 00:30:22
Bottle 是一个非常精致的WSGI框架,它提供了 Python Web开发中需要的基本支持:URL路由,Request/Response对象封装,模板支持,与WSGI服务器集成支持。整个框架的全部代码约有 2000行,它的核心部分没有其他任何依赖,只要有Python环境就可以运行。 Bottle适用于小型的Web开发,在应用程序规模比较小的情况下可以实现快速开发。但是由于自身功能所限,对于大型的Web程序,Bottle的功能略显不足,程序员需要手动管理模块、数据库、配置等等,与Pylons等框架相比Bottle的优势就难以体现出来了。 快速入门 通过一个简单的、典型的例子描述Bottle的使用: from bottle import Bottle, run, mako_view, request myapp = Bottle ( ) @myapp. get ( '/hello/:name/:count# \\ d+#' ) @mako_view ( 'hello' ) def hello ( name, count ) : ip = request. environ . get ( 'REMOTE_ADDR' ) return dict ( n=name, c= int ( count ) , ip=ip ) run ( app=myapp ) 我们创建一个Bottle对象

浅析Android中的消息机制

[亡魂溺海] 提交于 2019-12-06 23:46:31
在分析Android消息机制之前,我们先来看一段代码: 01 public class MainActivity extends Activity implements View.OnClickListener { 02 03 private TextView stateText; 04 private Button btn; 05 06 @Override 07 public void onCreate(Bundle savedInstanceState) { 08 super.onCreate(savedInstanceState); 09 setContentView(R.layout.main); 10 stateText = (TextView) findViewById(R.id.tv); 11 btn = (Button) findViewById(R.id.btn); 12 13 btn.setOnClickListener(this); 14 } 15 16 @Override 17 public void onClick(View v) { 18 new WorkThread().start(); 19 } 20 21 //工作线程 22 private class WorkThread extends Thread { 23 @Override 24