我有一个CEdit文本框,它是属性窗格的一部分,只允许数值(正整数).当人们输入非数字值时,该框工作正常,但当他们删除框中的值时会弹出一个对话框,说:"请输入一个正整数."
情况如下:
1.我在框中有一个数字(比如20).
我删除了这个号码.
3.我收到错误对话框.
有谁能告诉我如何拦截这个事件并在那里放一个默认值?
这是我的属性窗格的样子:
const int DEFAULT_VALUE = 20;
class MyPropertyPane:public CPropertyPane
{
//....
private:
CEdit m_NumericBox;
int m_value;
//....
public:
afx_msg void OnEnChangeNumericBox();
//....
}
void MyPropertyPane::MyPropertyPane()
{
// Set a default value
m_value = DEFAULT_VALUE;
}
//....
void MyPropertyPane::DoDataExchange(CDataExchange* pDX)
{
DDX_Control(pDX, IDC_NUMERIC_BOX, m_NumericBox);
// this sets the displayed value to 20
DDX_Text(pDX, IDC_NUMERIC_BOX, m_value);
}
//....
void MyPropertyPane::OnEnChangeNumericBox()
{
// Somebody deleted the value in the box and I got an event
// saying …Run Code Online (Sandbox Code Playgroud) public class PlayText extends Thread {
private int duration;
private String text;
private PlayerScreen playerscrn;
public PlayText(String text, int duration) {
this.duration = duration;
this.text = text;
this.playerscrn = (PlayerScreen)UiApplication.getUiApplication().getActiveScreen();
}
public void run() {
synchronized(UiApplication.getEventLock()) {
try{
RichTextField text1player = new RichTextField(this.text, Field.NON_FOCUSABLE);
playerscrn.add(text1player);
playerscrn.invalidate();
Thread.sleep(this.duration);
RichTextField text2player = new RichTextField("hahhaha", Field.NON_FOCUSABLE);
playerscrn.add(text2player);
playerscrn.invalidate();
Thread.sleep(1000);
RichTextField text3player = new RichTextField("Done", Field.NON_FOCUSABLE);
playerscrn.add(text3player);
playerscrn.invalidate();
}catch(Exception e){
System.out.println("I HAVE AN ERROR");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我正在尝试创建一个小型文本播放器.
而不是逐个获取所有文本标签,像
显示text1player之类的东西
等待this.duration毫秒
显示text2player
等待1000毫秒 …
嘿所有 - 这个代码在我试图清理处理程序的方式可能有点乱,因为我一直试图追踪崩溃发生的地方......
我有一个对话框活动,显示一个密码条目,其中一个进度条由一个线程和处理程序设置动画...
似乎当我试图查看进度条是否完成,并试图杀死线程时,我正在做的事情的方式是当我尝试去一个新的活动时弄乱一些东西 - 即以某种方式调用一个功能没有任何返回到什么?
public class RMO_Dialog extends Activity {
private ProgressBar progbar;
private Button dialogOK;
private EditText dialogPass;
private SharedPreferences prefs;
private String pass;
private int increment=10;
private Thread background;
private Boolean commCalled=false;
public void callCommunications(){
progbar.setVisibility(0);
progbar.setProgress(0);
background.stop();
Toast.makeText(getApplicationContext(), "Call communication should happen once.", Toast.LENGTH_LONG).show();
// Intent i = new Intent();
// i.setClass(RMO_Dialog.this, RMO_Comm.class);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(i);
// finish();
}
public void buzzUser(){
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
int dot = 200; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spark并行化集合,文档中的示例似乎不起作用:
List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
JavaRDD<Integer> distData = sc.parallelize(data);
Run Code Online (Sandbox Code Playgroud)
我正在LabeledPoint从记录中创建一个s 列表,每个记录包含数据点(double[])和标签(默认值:true/false).
public List<LabeledPoint> createLabeledPoints(List<ESRecord> records) {
List<LabeledPoint> points = new ArrayList<>();
for (ESRecord rec : records) {
points.add(new LabeledPoint(
rec.defaulted ? 1.0 : 0.0, Vectors.dense(rec.toDataPoints())));
}
return points;
}
public void test(List<ESRecord> records) {
SparkConf conf = new SparkConf().setAppName("SVM Classifier Example");
SparkContext sc = new SparkContext(conf);
List<LabeledPoint> points = createLabeledPoints(records);
JavaRDD<LabeledPoint> data = sc.parallelize(points);
...
}
Run Code Online (Sandbox Code Playgroud)
parallelize的函数签名不再是一个参数,这是它在spark-mllib_2.11 v1.3.0中的样子: sc.parallelize(seq, numSlices, evidence$1)
那么关于如何使这个工作的任何想法?
java artificial-intelligence machine-learning apache-spark apache-spark-mllib
我怎样才能使这个通用?
class AtomicReference
{
private Object _value;
public AtomicReference()
{
_value = new Object();
}
public AtomicReference(Object value)
{
OptimisticSet(value);
}
public Object CompareAndSet(Object newValue)
{
return Interlocked.Exchange(ref _value, newValue);
}
public void OptimisticSet(Object newValue)
{
do {
} while (_value == Interlocked.CompareExchange(ref _value, _value, newValue));
}
public Object Get()
{
return _value;
}
}
Run Code Online (Sandbox Code Playgroud)
我失败的尝试:
class AtomicReference<T>
{
private T _value;
public AtomicReference()
{
}
public AtomicReference(T value)
{
Set(value);
}
public T CompareAndSet(T newValue)
{
// _value is …Run Code Online (Sandbox Code Playgroud) 我得到了一些奇怪的行为...当我dummyText List在ThreadTest方法中迭代时,我得到一个超出范围异常(ArgumentOutOfRangeException)的索引,但如果我删除线程并且我只打印出文本,那么一切正常.
这是我的主要方法:
public static Object sync = new Object();
static void Main(string[] args)
{
ThreadTest();
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
此方法抛出异常:
private static void ThreadTest()
{
Console.WriteLine("Running ThreadTest");
Console.WriteLine("Running ThreadTest");
List<String> dummyText = new List<string>()
{ "One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten"};
for (int i = 0; i < dummyText.Count; i++)
{
Thread t = new Thread(() => PrintThreadName(dummyText[i])); // <-- Index out of range?!?
t.Name = …Run Code Online (Sandbox Code Playgroud) 我在XNA中有一个需要进行网络呼叫的游戏.在更新方法中,我确定需要发送的内容,然后将其添加到要发送的内容列表中.然后我运行网络呼叫.这显然会减慢应用程序的速度.所以我首先尝试在更新中创建这样的新线程,使其在单独的线程上执行:
Thread thread;
thread = new Thread(
new ThreadStart(DoNetworkThing));
thread.Start();
Run Code Online (Sandbox Code Playgroud)
我认为创建线程有开销等,导致这更慢.最后,我制作了一个方法,while(true){DoNetworkThing();}其中包含循环并一遍又一遍地运行网络调用(它确实检查它是否已经忙于一个,以及是否有要发送的东西).我在一个线程中调用LoadContent方法的方法,因此它将在自己的线程中与游戏一起运行.但那也很慢.
那么我做错了什么?这样做的最佳方式是什么?谢谢
我正在阅读一些ASP.NET教程,我正在研究的第一个是如何制作母版页.当我创建母版页时,我收到一个错误:
Value cannot be null. Parameter name: frameworkName
Run Code Online (Sandbox Code Playgroud)
它出现在我的母版页(MasterPage.master)的第一行,它是创建的默认页面 - 我根本没有修改它:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
Run Code Online (Sandbox Code Playgroud)
有人能告诉我frameworkName参数是什么,我该如何摆脱这个错误?仅供参考:我正在使用Visual Studio 2010.
C# 是否有类似于 C++ 的CHAR_BIT 的东西?
更新:
基本上,我正在尝试计算无分支的abs,这里是C++版本:
// Compute the integer absolute value (abs) without branching
int v; // we want to find the absolute value of v
unsigned int r; // the result goes here
int const mask = v >> sizeof(int) * CHAR_BIT - 1;
r = (v ^ mask) - mask;
Run Code Online (Sandbox Code Playgroud)
这是我的 C# 版本:
private int Abs(int value)
{
int mask = value >> sizeof(int) * 8 - 1;
return ((value ^ mask) - mask); …Run Code Online (Sandbox Code Playgroud) 我正在关注Ricky的Twitterizer示例(在我的最后进行了一些修改),但是当我尝试发送身份验证请求时,我收到了"401 Unauthorized"异常:
{Twitterizer.TwitterizerException: The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Twitterizer.WebRequestBuilder.ExecuteRequest()
at Twitterizer.OAuthUtility.GetRequestToken(String consumerKey, String consumerSecret, String callbackAddress)
--- End of inner exception stack trace ---
at Twitterizer.OAuthUtility.GetRequestToken(String consumerKey, String consumerSecret, String callbackAddress)
at MyProject.Controllers.AccountController.Authenticate(String oauthToken, String oauthVerifier, String returnUrl) in C:\path\to\my\website\Controllers\AccountController.cs:line 78}
Run Code Online (Sandbox Code Playgroud)
我有私有成员变量,它包含我的消费者密钥和消费者秘密:
// I obtain my consumer key and the consumer secret from the web config
private static readonly string _twitterConsumerKey = …Run Code Online (Sandbox Code Playgroud) c# ×5
c++ ×2
java ×2
android ×1
apache-spark ×1
asp.net ×1
blackberry ×1
cedit ×1
concurrency ×1
events ×1
exception ×1
for-loop ×1
generics ×1
handler ×1
lambda ×1
master-pages ×1
mfc ×1
numeric ×1
twitter ×1
twitterizer ×1
uilabel ×1
xna ×1