这是我的代码:
{
double dps1 = 2;
double count;
DispatcherTimer DPS = new DispatcherTimer();
public MainWindow()
{
InitializeComponent();
DPS.Tick += new EventHandler(DPS_tick);
DPS.Interval = new TimeSpan(1);
}
private void DPS_tick(object sender, EventArgs e)
{
count += dps1 / 2500;
lbl.Content = count;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DPS.Start();
}
以下是实际计划的GIF:https://i.imgur.com/d91bxJD.gifv
答案 0 :(得分:0)
首先,您使用UI调度程序安排计时器滴答。要证明这一点,请将以下内容添加到构造函数中。
External Native Build Issues
Build command failed.
Error while executing process /home/m/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/m/AndroidStudioProjects/NDKTest3/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/debug/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
local c includes= /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../api /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccmain /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccstruct /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../classify /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../cutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../dict /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../image /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../textord /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../third_party /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../wordrec /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../opencl /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../viewer /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../../leptonica/include
local path=/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni
local src files = ../../api/baseapi.cpp ../../api/capi.cpp ../../api/renderer.cpp ../../ccmain/adaptions.cpp ../../ccmain/applybox.cpp ../../ccmain/control.cpp ../../ccmain/docqual.cpp ../../ccmain/equationdetect.cpp ../../ccmain/fixspace.cpp ../../ccmain/fixxht.cpp ../../ccmain/linerec.cpp ../../ccmain/ltrresultiterator.cpp ../../ccmain/osdetect.cpp ../../ccmain/output.cpp ../../ccmain/pageiterator.cpp ../../ccmain/pagesegmain.cpp ../../ccmain/pagewalk.cpp ../../ccmain/paragraphs.cpp ../../ccmain/paramsd.cpp ../../ccmain/par_control.cpp ../../ccmain/pgedit.cpp ../../ccmain/recogtraining.cpp ../../ccmain/reject.cpp ../../ccmain/resultiterator.cpp ../../ccmain/superscript.cpp ../../ccmain/tessbox.cpp ../../ccmain/tessedit.cpp ../../ccmain/tesseractclass.cpp ../../ccmain/tessvars.cpp ../../ccmain/tfacepp.cpp ../../ccmain/thresholder.cpp ../../ccmain/werdit.cpp ../../ccstruct/blamer.cpp ../../ccstruct/blobbox.cpp ../../ccstruct/blobs.cpp ../../ccstruct/blread.cpp ../../ccstruct/boxread.cpp ../../ccstruct/boxword./home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk:48: *cp** Android NDK:p Aborting. .. . Stop.
/../ccstruct/ccstruct.cpp ../../ccstruct/coutln.cpp ../../ccstruct/detlinefit.cpp ../../ccstruct/dppoint.cpp ../../ccstruct/fontinfo.cpp ../../ccstruct/genblob.cpp ../../ccstruct/imagedata.cpp ../../ccstruct/linlsq.cpp ../../ccstruct/matrix.cpp ../../ccstruct/mod128.cpp ../../ccstruct/normalis.cpp ../../ccstruct/ocrblock.cpp ../../ccstruct/ocrpara.cpp ../../ccstruct/ocrrow.cpp ../../ccstruct/otsuthr.cpp ../../ccstruct/pageres.cpp ../../ccstruct/params_training_featdef.cpp ../../ccstruct/pdblock.cpp ../../ccstruct/points.cpp ../../ccstruct/polyaprx.cpp ../../ccstruct/polyblk.cpp ../../ccstruct/publictypes.cpp ../../ccstruct/quadlsq.cpp ../../ccstruct/quspline.cpp ../../ccstruct/ratngs.cpp ../../ccstruct/rect.cpp ../../ccstruct/rejctmap.cpp ../../ccstruct/seam.cpp ../../ccstruct/split.cpp ../../ccstruct/statistc.cpp ../../ccstruct/stepblob.cpp ../../ccstruct/vecfuncs.cpp ../../ccstruct/werd.cpp ../../ccutil/ambigs.cpp ../../ccutil/basedir.cpp ../../ccutil/bits16.cpp ../../ccutil/bitvector.cpp ../../ccutil/ccutil.cpp ../../ccutil/clst.cpp ../../ccutil/elst2.cpp ../../ccutil/elst.cpp ../../ccutil/errcode.cpp ../../ccutil/globaloc.cpp ../../ccutil/indexmapbidi.cpp ../../ccutil/mainblk.cpp ../../ccutil/memry.cpp ../../ccutil/params.cpp ../../ccutil/scanutils.cpp ../../ccutil/serialis.cpp ../../ccutil/strngs.cpp ../../ccutil/tessdatamanager.cpp ../../ccutil/tprintf.cpp ../../ccutil/unicharcompress.cpp ../../ccutil/unichar.cpp ../../ccutil/unicharmap.cpp ../../ccutil/unicharset.cpp ../../ccutil/unicodes.cpp ../../ccutil/universalambigs.cpp ../../classify/adaptive.cpp ../../classify/adaptmatch.cpp ../../classify/blobclass.cpp ../../classify/classify.cpp ../../classify/cluster.cpp ../../classify/clusttool.cpp ../../classify/cutoffs.cpp ../../classify/errorcounter.cpp ../../classify/featdefs.cpp ../../classify/float2int.cpp ../../classify/fpoint.cpp ../../classify/intfeaturedist.cpp ../../classify/intfeaturemap.cpp ../../classify/intfeaturespace.cpp ../../classify/intfx.cpp ../../classify/intmatcher.cpp ../../classify/intproto.cpp ../../classify/kdtree.cpp ../../classify/mastertrainer.cpp ../../classify/mf.cpp ../../classify/mfdefs.cpp ../../classify/mfoutline.cpp ../../classify/mfx.cpp ../../classify/normfeat.cpp ../../classify/normmatch.cpp ../../classify/ocrfeatures.cpp ../../classify/outfeat.cpp ../../classify/picofeat.cpp ../../classify/protos.cpp ../../classify/sampleiterator.cpp ../../classify/shapeclassifier.cpp ../../classify/shapetable.cpp ../../classify/tessclassifier.cpp ../../classify/trainingsample.cpp ../../classify/trainingsampleset.cpp ../../cutil/bitvec.cpp ../../cutil/callcpp.cpp ../../cutil/cutil_class.cpp ../../cutil/cutil.cpp ../../cutil/danerror.cpp ../../cutil/efio.cpp ../../cutil/emalloc.cpp ../../cutil/oldlist.cpp ../../cutil/structures.cpp ../../dict/context.cpp ../../dict/dawg_cache.cpp ../../dict/dawg.cpp ../../dict/dict.cpp ../../dict/hyphen.cpp ../../dict/permdawg.cpp ../../dict/stopper.cpp ../../dict/trie.cpp ../../textord/alignedblob.cpp ../../textord/baselinedetect.cpp ../../textord/bbgrid.cpp ../../textord/blkocc.cpp ../../textord/blobgrid.cpp ../../textord/ccnontextdetect.cpp ../../textord/cjkpitch.cpp ../../textord/colfind.cpp ../../textord/colpartition.cpp ../../textord/colpartitiongrid.cpp ../../textord/colpartitionset.cpp ../../textord/devanagari_processing.cpp ../../textord/drawedg.cpp ../../textord/drawtord.cpp ../../textord/edgblob.cpp ../../textord/edgloop.cpp ../../textord/equationdetectbase.cpp ../../textord/fpchop.cpp ../../textord/gap_map.cpp ../../textord/imagefind.cpp ../../textord/linefind.cpp ../../textord/makerow.cpp ../../textord/oldbasel.cpp ../../textord/pithsync.cpp ../../textord/pitsync1.cpp ../../textord/scanedg.cpp ../../textord/sortflts.cpp ../../textord/strokewidth.cpp ../../textord/tabfind.cpp ../../textord/tablefind.cpp ../../textord/tablerecog.cpp ../../textord/tabvector.cpp ../../textord/textlineprojection.cpp ../../textord/textord.cpp ../../textord/topitch.cpp ../../textord/tordmain.cpp ../../textord/tospace.cpp ../../textord/tovars.cpp ../../textord/underlin.cpp ../../textord/wordseg.cpp ../../textord/workingpartset.cpp ../../viewer/scrollview.cpp ../../viewer/svmnode.cpp ../../viewer/svpaint.cpp ../../viewer/svutil.cpp ../../wordrec/associate.cpp ../../wordrec/chop.cpp ../../wordrec/chopper.cpp ../../wordrec/drawfx.cpp ../../wordrec/findseam.cpp ../../wordrec/gradechop.cpp ../../wordrec/language_model.cpp ../../wordrec/lm_consistency.cpp ../../wordrec/lm_pain_points.cpp ../../wordrec/lm_state.cpp ../../wordrec/outlines.cpp ../../wordrec/params_model.cpp ../../wordrec/pieces.cpp ../../wordrec/plotedges.cpp ../../wordrec/render.cpp ../../wordrec/segsearch.cpp ../../wordrec/tface.cpp ../../wordrec/wordclass.cpp ../../wordrec/wordrec.cpp
Android NDK: /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk: Cannot find module with tag 'base/port' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
Build command failed.
Error while executing process /home/m/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/m/AndroidStudioProjects/NDKTest3/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-21 NDK_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=/home/m/AndroidStudioProjects/NDKTest3/app/build/intermediates/ndkBuild/release/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
local c includes= /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../api /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccmain /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccstruct /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../ccutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../classify /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../cutil /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../dict /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../image /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../textord /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../third_party /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../wordrec /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../opencl /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../viewer /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/../../../leptonica/include
local path=/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni
local src files = ../../api/baseapi.cpp ../../api/capi.cpp ../../api/renderer.cpp ../../ccmain/adaptions.cpp ../../ccmain/applybox.cpp ../../ccmain/control.cpp ../../ccmain/docqual.cpp ../../ccmain/equationdetect.cpp ../../ccmain/fixspace.cpp ../../ccmain/fixxht.cpp ../../ccmain/linerec.cpp ../../ccmain/ltrresultiterator.cpp ../../ccmain/osdetect.cpp ../../ccmain/output.cpp ../../ccmain/pageiterator.cpp ../../ccmain/pagesegmain.cpp ../../ccmain/pagewalk.cpp ../../ccmain/paragraphs.cpp ../../ccmain/paramsd.cpp ../../ccmain/par_control.cpp ../../ccmain/pgedit.cpp ../../ccmain/recogtraining.cpp ../../ccmain/reject.cpp ../../ccmain/resultiterator.cpp ../../ccmain/superscript.cpp ../../ccmain/tessbox.cpp ../../ccmain/tessedit.cpp ../../ccmain/tesseractclass.cpp ../../ccmain/tessvars.cpp ../../ccmain/tfacepp.cpp ../../ccmain/thresholder.cpp ../../ccmain/werdit.cpp ../../ccstruct/blamer.cpp ../../ccstruc/home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk:48: *** Android NDK: Aborting. . Stop.
t/blobbox.cpp ../../ccstruct/blobs.cpp ../../ccstruct/blread.cpp ../../ccstruct/boxread.cpp ../../ccstruct/boxword.cpp ../../ccstruct/ccstruct.cpp ../../ccstruct/coutln.cpp ../../ccstruct/detlinefit.cpp ../../ccstruct/dppoint.cpp ../../ccstruct/fontinfo.cpp ../../ccstruct/genblob.cpp ../../ccstruct/imagedata.cpp ../../ccstruct/linlsq.cpp ../../ccstruct/matrix.cpp ../../ccstruct/mod128.cpp ../../ccstruct/normalis.cpp ../../ccstruct/ocrblock.cpp ../../ccstruct/ocrpara.cpp ../../ccstruct/ocrrow.cpp ../../ccstruct/otsuthr.cpp ../../ccstruct/pageres.cpp ../../ccstruct/params_training_featdef.cpp ../../ccstruct/pdblock.cpp ../../ccstruct/points.cpp ../../ccstruct/polyaprx.cpp ../../ccstruct/polyblk.cpp ../../ccstruct/publictypes.cpp ../../ccstruct/quadlsq.cpp ../../ccstruct/quspline.cpp ../../ccstruct/ratngs.cpp ../../ccstruct/rect.cpp ../../ccstruct/rejctmap.cpp ../../ccstruct/seam.cpp ../../ccstruct/split.cpp ../../ccstruct/statistc.cpp ../../ccstruct/stepblob.cpp ../../ccstruct/vecfuncs.cpp ../../ccstruct/werd.cpp ../../ccutil/ambigs.cpp ../../ccutil/basedir.cpp ../../ccutil/bits16.cpp ../../ccutil/bitvector.cpp ../../ccutil/ccutil.cpp ../../ccutil/clst.cpp ../../ccutil/elst2.cpp ../../ccutil/elst.cpp ../../ccutil/errcode.cpp ../../ccutil/globaloc.cpp ../../ccutil/indexmapbidi.cpp ../../ccutil/mainblk.cpp ../../ccutil/memry.cpp ../../ccutil/params.cpp ../../ccutil/scanutils.cpp ../../ccutil/serialis.cpp ../../ccutil/strngs.cpp ../../ccutil/tessdatamanager.cpp ../../ccutil/tprintf.cpp ../../ccutil/unicharcompress.cpp ../../ccutil/unichar.cpp ../../ccutil/unicharmap.cpp ../../ccutil/unicharset.cpp ../../ccutil/unicodes.cpp ../../ccutil/universalambigs.cpp ../../classify/adaptive.cpp ../../classify/adaptmatch.cpp ../../classify/blobclass.cpp ../../classify/classify.cpp ../../classify/cluster.cpp ../../classify/clusttool.cpp ../../classify/cutoffs.cpp ../../classify/errorcounter.cpp ../../classify/featdefs.cpp ../../classify/float2int.cpp ../../classify/fpoint.cpp ../../classify/intfeaturedist.cpp ../../classify/intfeaturemap.cpp ../../classify/intfeaturespace.cpp ../../classify/intfx.cpp ../../classify/intmatcher.cpp ../../classify/intproto.cpp ../../classify/kdtree.cpp ../../classify/mastertrainer.cpp ../../classify/mf.cpp ../../classify/mfdefs.cpp ../../classify/mfoutline.cpp ../../classify/mfx.cpp ../../classify/normfeat.cpp ../../classify/normmatch.cpp ../../classify/ocrfeatures.cpp ../../classify/outfeat.cpp ../../classify/picofeat.cpp ../../classify/protos.cpp ../../classify/sampleiterator.cpp ../../classify/shapeclassifier.cpp ../../classify/shapetable.cpp ../../classify/tessclassifier.cpp ../../classify/trainingsample.cpp ../../classify/trainingsampleset.cpp ../../cutil/bitvec.cpp ../../cutil/callcpp.cpp ../../cutil/cutil_class.cpp ../../cutil/cutil.cpp ../../cutil/danerror.cpp ../../cutil/efio.cpp ../../cutil/emalloc.cpp ../../cutil/oldlist.cpp ../../cutil/structures.cpp ../../dict/context.cpp ../../dict/dawg_cache.cpp ../../dict/dawg.cpp ../../dict/dict.cpp ../../dict/hyphen.cpp ../../dict/permdawg.cpp ../../dict/stopper.cpp ../../dict/trie.cpp ../../textord/alignedblob.cpp ../../textord/baselinedetect.cpp ../../textord/bbgrid.cpp ../../textord/blkocc.cpp ../../textord/blobgrid.cpp ../../textord/ccnontextdetect.cpp ../../textord/cjkpitch.cpp ../../textord/colfind.cpp ../../textord/colpartition.cpp ../../textord/colpartitiongrid.cpp ../../textord/colpartitionset.cpp ../../textord/devanagari_processing.cpp ../../textord/drawedg.cpp ../../textord/drawtord.cpp ../../textord/edgblob.cpp ../../textord/edgloop.cpp ../../textord/equationdetectbase.cpp ../../textord/fpchop.cpp ../../textord/gap_map.cpp ../../textord/imagefind.cpp ../../textord/linefind.cpp ../../textord/makerow.cpp ../../textord/oldbasel.cpp ../../textord/pithsync.cpp ../../textord/pitsync1.cpp ../../textord/scanedg.cpp ../../textord/sortflts.cpp ../../textord/strokewidth.cpp ../../textord/tabfind.cpp ../../textord/tablefind.cpp ../../textord/tablerecog.cpp ../../textord/tabvector.cpp ../../textord/textlineprojection.cpp ../../textord/textord.cpp ../../textord/topitch.cpp ../../textord/tordmain.cpp ../../textord/tospace.cpp ../../textord/tovars.cpp ../../textord/underlin.cpp ../../textord/wordseg.cpp ../../textord/workingpartset.cpp ../../viewer/scrollview.cpp ../../viewer/svmnode.cpp ../../viewer/svpaint.cpp ../../viewer/svutil.cpp ../../wordrec/associate.cpp ../../wordrec/chop.cpp ../../wordrec/chopper.cpp ../../wordrec/drawfx.cpp ../../wordrec/findseam.cpp ../../wordrec/gradechop.cpp ../../wordrec/language_model.cpp ../../wordrec/lm_consistency.cpp ../../wordrec/lm_pain_points.cpp ../../wordrec/lm_state.cpp ../../wordrec/outlines.cpp ../../wordrec/params_model.cpp ../../wordrec/pieces.cpp ../../wordrec/plotedges.cpp ../../wordrec/render.cpp ../../wordrec/segsearch.cpp ../../wordrec/tface.cpp ../../wordrec/wordclass.cpp ../../wordrec/wordrec.cpp
Android NDK: /home/m/AndroidStudioProjects/NDKTest3/jni/../tesseract/android/jni/Android.mk: Cannot find module with tag 'base/port' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
你会注意到我是对的。因此,当您摆动鼠标时,UI线程正忙于鼠标事件,正如Hans所说的那样,优先级高于计时器滴答。不管它。
你可以通过使用在后台线程上运行的不同计时器实现来解决这个问题,然后将其传递到UI线程以在tick上更新UI。
我是MVVM的粉丝,绑定会自动处理UI线程上的调用更新,所以我的repro与你的不同。
首先,在UI中为标签添加绑定。
if(DPS.Dispatcher != Dispatcher.CurrentDispatcher || // UI thread, UI dispatcher
DPS.Dispatcher != Application.Current.Dispatcher || // Also the UI dispatcher
DPS.Dispatcher != Dispatcher) // the window's dispatcher
throw new InvalidOperationException("Will is wrong");
我们将在按钮上重复使用Click事件,为此创建一个ICommand有点过分。接下来,更新您的Window代码,使其如下所示
<Label Content="{Binding Count}" />
我使用System.Windows.Threading.Timer来处理我的刻度,其间隔为ms(.0001ms是刻度,粗略排序)。如果您运行此示例,您的UI将不再滞后。