我想用C#做一个简单的Countdown-Application作为例子.
对于第一个和最基本的版本,我使用Label来显示剩余的当前时间(以秒为单位)和一个Button来开始倒计时.Button的Click-Event实现如下:
private void ButtonStart_Click(object sender, RoutedEventArgs e)
{
_time = 60;
while (_time > 0)
{
_time--;
this.labelTime.Content = _time + "s";
System.Threading.Thread.Sleep(1000);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当用户单击按钮时,实际倒计时(因为应用程序冻结(由于Sleep())所选的时间量,但Label的上下文未刷新.
我做的事情一般是错的(当谈到线程时)或者它只是UI的一个问题?
谢谢您的回答!我现在使用System.Windows.Threading.DispatcherTimer来做你告诉我的事情.一切正常,所以这个问题得到正式回答;)
对于那些感兴趣的人:这是我的代码(基本部分)
public partial class WindowCountdown : Window
{
private int _time;
private DispatcherTimer _countdownTimer;
public WindowCountdown()
{
InitializeComponent();
_countdownTimer = new DispatcherTimer();
_countdownTimer.Interval = new TimeSpan(0,0,1);
_countdownTimer.Tick += new EventHandler(CountdownTimerStep);
}
private void ButtonStart_Click(object sender, RoutedEventArgs e)
{
_time = 10;
_countdownTimer.Start();
}
private void CountdownTimerStep(object sender, EventArgs e)
{
if …
Run Code Online (Sandbox Code Playgroud) 我想在向量中访问类型擦除类型的getter.getter标记为const.不知何故,const-ness不会传播到boost :: any包装器对象.最小的例子
#include <iostream>
#include <vector>
#include <boost/mpl/vector.hpp>
#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/member.hpp>
using namespace boost;
using namespace boost::type_erasure;
BOOST_TYPE_ERASURE_MEMBER((has_test), test, 1)
using AnyTest = any<mpl::vector<copy_constructible<>,
has_test<int(double)>,
relaxed>>;
struct ATest {
int test(double x) const {
return 5;
}
};
int main() {
auto xs = std::vector<AnyTest>{};
xs.push_back(ATest{});
for (const auto& x : xs) {
std::cout << x.test(42.0) << '\n';
}
}
Run Code Online (Sandbox Code Playgroud)
导致错误说
clang++ -O3 -std=c++14 minimal.cc -o minimal
minimal.cc:28:18: error: member function 'test' not viable: 'this' argument has type …
Run Code Online (Sandbox Code Playgroud) 我在Ubuntu 12.04上使用CERN的ROOT时偶然发现了这个非常烦人的问题,但我认为这是一个更普遍的问题.
我有一些带有外部引用的C++代码,我使用以下makefile编译和链接.在我的Mac OS X 10.8和服务器SL5上工作正常.
CXX=clang++
CXXFLAGS=-Wall -O2 -g $(shell root-config --cflags --libs)
testroot: testroot.cc
Run Code Online (Sandbox Code Playgroud)
它评估为
clang++ -Wall -O2 -g -pthread -m64 -I/opt/ROOT/5.34.05/include/root -L/opt/ROOT/5.34.05/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic testroot.cc -o testroot
Run Code Online (Sandbox Code Playgroud)
这给了我Ubuntu服务器上未定义的引用和链接器错误.我已经尝试过设置libs,LDFLAGS
但它会产生相同的结果.当我手动编译它并将源文件和-o选项放在库之前时,它编译没有问题.
从其他线程,我认为命令的顺序可以重要,但我想知道它为什么在某些机器上,而在其他机器上没有.即使订单很重要,我认为make
它足够聪明,可以自行解决.
现在的问题是:我怎样才能解决这个问题?我是否必须使用不同版本的make或ld?我必须修改我的makefile吗?
提前致谢!