采用Callable的Xamarin Executor(Xamarin Executor that takes Callable)
第一部分
嗨,我正在尝试更改以下代码以使用Callable而不是Runnable,因为我希望提供给Executor的函数返回数据。
using Android.App; using Android.OS; using Android.Widget; using Java.Util.Concurrent; using Java.Lang; namespace ServiceExecutor { [Activity(Label = "SomeActivity")] public class SomeActivity : Activity { TextView tv1; Runnable r; static IExecutorService exe = Executors.NewSingleThreadExecutor(); protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); tv1 = FindViewById<TextView>(Resource.Id.textView1); for (int i = 0; i < 4; i++) { r = new Runnable(() => function(i)); exe.Submit(r); } } public void function(int i) { RunOnUiThread(() => tv1.Text += "function " + i.ToString() + "\r\n"); Thread.Sleep(2000); } } }
我在Java中找到了一些例子,但是当我试图在C#中复制代码时,缺少主类Callable,并且只有ICallable,我无法实例化。 不幸的是,Xamarin文档也提供了Java示例!
如果有人能帮忙,我将不胜感激!
第二部分
完整的设计理念是一个Service,它有这个嵌入式Executor来顺序运行任务。 顺序执行是非常重要的,因为该服务将与蓝牙接口具有连续的套接字连接,并且一次只能处理一个蓝牙请求(任务)。 最初我想使用IntentService,但我希望服务在应用程序的整个生命周期中都是活动的,否则对于每个蓝牙请求,套接字必须重新连接。
任何有关设计方法的建议也将受到赞赏!
Part I
Hi, I am trying to alter the following piece of code to take Callable instead of Runnable, because I want the functions that are fed to the Executor to return data.
using Android.App; using Android.OS; using Android.Widget; using Java.Util.Concurrent; using Java.Lang; namespace ServiceExecutor { [Activity(Label = "SomeActivity")] public class SomeActivity : Activity { TextView tv1; Runnable r; static IExecutorService exe = Executors.NewSingleThreadExecutor(); protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); tv1 = FindViewById<TextView>(Resource.Id.textView1); for (int i = 0; i < 4; i++) { r = new Runnable(() => function(i)); exe.Submit(r); } } public void function(int i) { RunOnUiThread(() => tv1.Text += "function " + i.ToString() + "\r\n"); Thread.Sleep(2000); } } }
I have found examples in Java but when I'm trying to replicate the code in C# the main class Callable is missing and there is only ICallable which I can't instantiate. Unfortunately the Xamarin documentation also gives Java examples!
I would appreciate if anyone could help!
Part II
The complete design idea is a Service the has this embedded Executor to run tasks sequentially. The sequential execution is cruicial because the service will have continuous socket connection with the bluetooth interface and only one bluetooth request (task) can be handled at a time. Initially I wanted to use IntentService but I want the service to be alive throughout the life of the application, otherwise for each bluetooth request the socket will have to reconnect.
Any advice for the design approach will also be appreciated!
原文:https://stackoverflow.com/questions/41737154
最满意答案
如果您正在使用
artisan optimize
,它会将PHP类编译为单个compiled.php
。此外,并非所有文件都是php,并非所有的php文件都被使用。
我希望httpd不使用php直接提供静态文件,测试根本不应该触及prod。
If you are using
artisan optimize
, it compiles PHP classes into singlecompiled.php
.Also, not all files are php, and not all php files are being used.
I'd expect static files to be served directly by httpd without using php, and tests should not to be touched on prod at all.
相关问答
更多-
如何使用PHP OPCache?(How to use PHP OPCache?)[2021-12-14]
安装 OpCache默认编译为PHP5.5 +。 但默认情况下禁用。 为了开始在PHP5.5 +中使用OpCache,你首先必须启用它。 为此,您必须执行以下操作。 php.ini下行添加到您的php.ini : zend_extension=/full/path/to/opcache.so (nix) zend_extension=C:\path\to\php_opcache.dll (win) 请注意,当路径包含空格时,您应该用引号括起来: zend_extension="C:\Program Fil ... -
是否需要opcache_compile_file()函数? 不,你不需要关心那个。 opcache自动运行,你无事可做。 Is the opcache_compile_file() function even needed? No, you don't need to care about that. The opcache works automatically, you have nothing to do.
-
php opcache缓存输出(php opcache caches output)[2022-03-03]
我得到了它。因为在opcache_get_configuration() : [opcache.revalidate_freq] => 60 I got it.because in opcache_get_configuration() : [opcache.revalidate_freq] => 60 -
最好的起点是官方的OPcache资源: http ://php.net/manual/en/book.opcache.php Best place to start would be with the official OPcache resource: http://php.net/manual/en/book.opcache.php
-
是的,它确实。 我不会完成整个过程,但ext/opcache/ZendAccelerator.c有逻辑 Yes it does. I won't go through the whole thing, but there is logic in ext/opcache/ZendAccelerator.c
-
PHP中的OPcache如何确定是否发生了命中?(How does OPcache in PHP determine whether a hit how occurred or not?)[2022-02-14]
您将PHP Opcache与HTTP缓存混淆。 PHP Opcache不缓存PHP页面的输出。 相反,它缓存PHP用于PHP源文件的内部表示,允许它在需要时立即执行,而不是每次请求页面时都要求PHP重新分析源文件。 You're confusing PHP Opcache with an HTTP cache. PHP Opcache doesn't cache the output of a PHP page. Instead, it caches the internal representation ... -
如果您正在使用artisan optimize ,它会将PHP类编译为单个compiled.php 。 此外,并非所有文件都是php,并非所有的php文件都被使用。 我希望httpd不使用php直接提供静态文件,测试根本不应该触及prod。 If you are using artisan optimize, it compiles PHP classes into single compiled.php. Also, not all files are php, and not all php files ...
-
OpCache没有缓存(OpCache not caching)[2022-04-11]
这看起来像是使用cgi而不是mod_php5 。 共享内存区域(SMA)用于两者,但它仅保留对后者的请求请求。 This looks like you are using cgi rather than mod_php5. The shared memory area (SMA) is used for both, but it only persists request-to-request for the latter. -
启用PHP7 Opcache(Enabling PHP7 Opcache)[2023-08-19]
我通过确保apache写入我创建的文件夹来修复此问题。 一旦完成,重新启动httpd使其工作。 I fixed this by making sure apache get write to the folders I created. Once that was done restarting httpd made it work. -
1)确保httpd.conf中存在两行 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so LoadModule fcgid_module modules/mod_fcgid.so 2)我继续向httpd.conf添加以下行
FcgidInitialEnv PATH "C:/wamp/bin/php/php5.5.12;C:/WINDOWS/system32" FcgidInitial ...