我最近提供了这个问题的答案:C# - 实时控制台输出重定向.
正如经常发生的那样,解释一些东西(这里的"东西"就是我解决类似问题的方式)会让你更加了解和/或就像这里的"oops"时刻一样.我意识到我的解决方案已实施,但有一个错误.这个bug没什么实际意义,但作为一个开发人员,它对我来说非常重要:我知道我的代码有可能爆炸,我不能轻易放松.
压缩bug是这个问题的目的.我为长篇介绍道歉,让我们变得肮脏.
我想构建一个允许我从控制台的标准输出接收输入的类Stream.控制台输出流是类型FileStream; 如果需要,实现可以转换为该实现.StreamReader杠杆作用已经存在相关联.
我需要在这个类中实现一件事来实现我想要的功能:异步"读取此刻可用的所有数据"操作.读到流的末尾是不可行的,因为除非进程关闭控制台输出句柄,否则流不会结束,并且它不会这样做,因为它是交互式的并且在继续之前期望输入.
我将使用该假设的异步操作来实现基于事件的通知,这对我的调用者来说会更方便.
该类的公共接口是这样的:
public class ConsoleAutomator {
public event EventHandler<ConsoleOutputReadEventArgs> StandardOutputRead;
public void StartSendingEvents();
public void StopSendingEvents();
}
Run Code Online (Sandbox Code Playgroud)
StartSendingEvents并StopSendingEvents做他们做广告的事情; 出于本讨论的目的,我们可以假设事件总是在不失一般性的情况下发送.
该类在内部使用这两个字段:
protected readonly StringBuilder inputAccumulator = new StringBuilder();
protected readonly byte[] buffer = new byte[256];
Run Code Online (Sandbox Code Playgroud)
该类的功能在以下方法中实现.为了让球滚动:
public void StartSendingEvents();
{
this.stopAutomation = false;
this.BeginReadAsync();
}
Run Code Online (Sandbox Code Playgroud)
要从Stream无阻塞中读取数据,并且不需要回车符,BeginRead则称为:
protected void BeginReadAsync()
{
if (!this.stopAutomation) {
this.StandardOutput.BaseStream.BeginRead(
this.buffer, 0, this.buffer.Length, this.ReadHappened, …Run Code Online (Sandbox Code Playgroud) 我用这段代码得到了这个错误:
for(std::vector<AguiTimedEvent*>::iterator it = timedEvents.begin();
it != timedEvents.end();)
{
if((*it)->expired())
{
(*it)->timedEventCallback();
delete (*it);
it = timedEvents.erase(it);
}
else
it++;
}
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?
定时事件有时会在调用其回调时推送新的事件,这可能会发生
谢谢
我想创建一个响应接收SMS消息并显示对话框的应用程序.如何在清单中注册接收器而不在活动中定义?
我试图将清单中的receiver/intent-filter标记保留在活动标记之外,但模拟器不会安装apk,因为没有启动活动.将BroadcastReceiver保持为主要活动会导致Logcat中出现"无法实例化活动"错误.
有帮助吗?
谢谢,Sunny
接收器类
public class SMSReceiver extends BroadcastReceiver {
// onCreat is invoked when an sms message is received.
// Message is attached to Intent via Bundle, stored in an Object
// array in the PDU format.
public void onReceive(Context context, Intent intent) {
// get the SMS message passed in from Bundle
Bundle bundle = intent.getExtras();
String bodyText = "";
String from = "";
if (bundle != null) {
//Retrieve sms message within Object array
Object[] pdus …Run Code Online (Sandbox Code Playgroud) 如果我做到这一点,那么Controller的功能就是处理POST数据,并通过Model在技术上改变应用程序的状态(例如DB).
据我所知,View也从模型中获取数据.
这就是我理解工作流程的方式:
客户端请求 - > App Front Controller- >(如果method = POST - > Controller) - > View- >返回客户端
这里Model用于Controller读取和写入数据以及View读取数据.
因此,每次加载页面时都不会使用控制器,事实上,只有在添加/更新应用程序数据时才使用控制器.大多数时候控制器被绕过.
那么,为什么几乎所有关于MVC的资源都在谈论Controller向视图发送数据?
我正在尝试使用类似MVC的模式编写应用程序.因此,在我的应用视图中,始终从模型中获取页面的数据.当Model更新时,我将特定的模型更新时间添加到Memcache.在运行时,每个View查找相关模型的上次更新时间,并生成此视图的上次缓存.如果在保存缓存之前更新了模型,则视图将读取缓存,否则将根据更新的模型重新渲染.
php model-view-controller frameworks design-patterns ruby-on-rails
应用程序启动时如何阅读应用程序设置?例如,对于某些游戏应用程序,您可以在iPhone设置应用程序中设置声音,振动设置.那么,该游戏应用程序启动时如何阅读这些设置?
我正在尝试将SVG图像显示在我的iPhone(或iPad)默认浏览器上,但我似乎无法只显示一个矩形.
示例:http://www.invalidpage.com/svg/svgtest.html
资源:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>SVG iPhone Test</title>
</head>
<body>
<div>
<svg width="500" height="220">
<rect x="2" y="2" width="496" height="216" stroke="#000" stroke-width="2px" fill="transparent"></rect>
</svg>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 在Windows XP中,使用Delphi,如何获取主卷?
我知道我可以使用keybd_event(VK_VOLUME_UP, 1, 0, 0);和设置和向下发送击键keybd_event(VK_VOLUME_DOWN, 1, 0, 0);,但我不知道如何获得音量的实际值.
如果将纬度或经度转换为double的公式为
((Degree) + (Minute) / 60 + (Second) / 3600) * ((South || West) ? -1 : 1)
那么从双精度解析度,分,秒的公式是什么?
有两个单独的方法来解析纬度和经度是有道理的,但我不知道如何解析双精度的度数,分钟,秒.
ParseLatitude(double value)
{
//value is South if negative, else is North.
}
ParseLongitude(double value)
{
//value is West if negative, else is East.
}
Run Code Online (Sandbox Code Playgroud)
示例坐标:
纬度:43.81234123
经度:-119.8374747
最后的代码来回转换,再次感谢Peter和James的回答.我不得不将值转换为Decimal,因为这是在Silverlight中使用而Math.Truncate(double)不可用):
public class Coordinate
{
public double Degrees { get; set; }
public double Minutes { get; set; }
public double Seconds { get; set; }
public CoordinatesPosition Position { get; …Run Code Online (Sandbox Code Playgroud) 如何返回链接所在行的id属性?我尝试了不同的变化,但我能得到的最好的是"未定义"......
html看起来像这样:
<tr id="30">
<td>Parker</td>
<td><a href="#" id="id783900" class="section-id">Select</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我试过的一件事是:
$("a.section-id").click(function() {
var parenttr = $(this).parent().parent().attr("id");
alert(parenttr);
});
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
$("a.section-id").click(function() {
var parenttr = $(this).parent('tr').attr("id");
alert(parenttr);
});
Run Code Online (Sandbox Code Playgroud) 我正在为Linux构建一个NPAPI插件,它使用XEmbed协议来处理由插件控制的窗口.我使用Gtk +附加到窗口,用GtkPlug包装XEmbed窗口.我想在窗口上渲染一个OpenGL表面(使用GtkGLExt)但是当我启用生成的OpenGL上下文时,我无法创建GLSL着色器; 实际上,查询glGetString(GL_VERSION)的值表明OpenGL的版本字符串已经从"2.1 NVIDIA ..."更改为"1.4(2.1 NIVIDIA ...)",这表明GL驱动程序已降低了OpenGL的功能.这个情况.
我无法找到任何直接引用在OpenGL功能上使用XEmbed位置的限制.有谁知道XEmbed是否有效地将OpenGL降级为固定管道?