搜档网
当前位置:搜档网 › ExecutorService取代Timer

ExecutorService取代Timer

ExecutorService取代Timer
ExecutorService取代Timer

《Java并发编程实战》一书提到的用ExecutorService取代Java Timer有几个理由,我认为其中最重要的理由是:

如果TimerTask抛出未检查的异常,Timer将会产生无法预料的行为。Timer线程并不捕获异常,所以TimerT ask抛出的未检查的异常会终止timer线程。这种情况下,Timer也不会再重新恢复线程的执行了;它错误的认为整个Timer都被取消了。此时,已经被安排但尚未执行的TimerTask永远不会再执行了,新的任务也不能被调度了。

stackoverflow上也有关于此问题的讨论:

https://www.sodocs.net/doc/4514809897.html,/questions/409932/java-timer-vs-executorservice

Timer的问题:

Java代码

1package com.ljn.timer;

2

3import java.util.Date;

4import java.util.Timer;

5

6/**

7* @author lijinnan

8* @date:2013-11-25 下午3:27:43

9*/

10public class TimerException {

11

12public static void main(String[] args) {

13System.out.println("start:" + new Date());

14Timer timer = new Timer();

15int delay = 1000;

16int period = 2000;

17timer.schedule(new OKT ask(), delay * 2, period); //"OKT ask"

does not get chance to execute

18timer.schedule(new ErrorT ask(), delay, period); //exception in "ErrorT ask" will terminate the Timer

19}

20

21/*输出:

22start:Mon Nov 25 17:49:53 CST 2013

23ErrorT ask is executing...

24error:Mon Nov 25 17:49:55 CST 2013

25Exception in thread "Timer-0" https://www.sodocs.net/doc/4514809897.html,ng.RuntimeException: something wrong

26at com.ljn.timer.ErrorTask.run(ErrorTask.java:14)

27*/

28

29}

用ExecutorService则正常:

Java代码

30package com.ljn.timer;

31

32import java.util.Date;

33import java.util.concurrent.Executors;

34import java.util.concurrent.ScheduledExecutorService;

35import java.util.concurrent.TimeUnit;

36

37/**

38* @author lijinnan

39* @date:2013-11-25 下午3:35:39

40*/

41public class ScheduledExecutorServiceTest {

42

43public static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);

44

45public static void main(String[] args){

46System.out.println("start:" + new Date());

47ErrorT ask errorT ask = new ErrorTask();

48OKT ask okT ask = new OKT ask();

49int delay = 1000;

50int period = 2000;

51scheduledExecutorService.scheduleAtFixedRate(errorTask, delay, period, https://www.sodocs.net/doc/4514809897.html,LISECONDS); //"ErrorTask" throws Exception and then stopes.

52scheduledExecutorService.scheduleAtFixedRate(okTask, delay * 2,

period, https://www.sodocs.net/doc/4514809897.html,LISECONDS); //"OKT ask" is executed periodically, not affected by "ErrorT ask"

53

54//scheduledExecutorService.shutdown();

55}

56

57/*

58start:Mon Nov 25 17:54:22 CST 2013

59ErrorT ask is executing...

60error occurs:Mon Nov 25 17:54:24 CST 2013

61OKT ask is executed:Mon Nov 25 17:54:24 CST 2013

62OKT ask is executed:Mon Nov 25 17:54:26 CST 2013

63OKT ask is executed:Mon Nov 25 17:54:28 CST 2013

64......

65*/

66

67}

另外开发中常常会让任务在每天的指定时间点运行,示例如下:

Java代码

68package com.ljn.timer;

69

70import java.util.Date;

71import java.util.concurrent.Executors;

72import java.util.concurrent.ScheduledExecutorService;

73import java.util.concurrent.TimeUnit;

74

75/**

76* @author lijinnan

77* @date:2013-11-25 下午5:18:55

78*/

79public class FixedDatetimeTaskTest {

80

81public static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

82

83public static void main(String[] args) throws Exception {

84System.out.println("start:" + new Date());

85

86//每天的02:30:00执行任务

87long delay = Helper.calcDelay(2, 30, 0);

88long period = Helper.ONE_DAY;

89scheduledExecutorService.scheduleAtFixedRate(new OKT ask(), delay, period, https://www.sodocs.net/doc/4514809897.html,LISECONDS);

90}

92}

文章中用到的其他类:

Java代码

93package com.ljn.timer;

94

95import java.util.Date;

96import java.util.TimerTask;

97

98public class ErrorT ask extends TimerTask {

99

100@Override

101public void run() {

102try {

103System.out.println("ErrorTask is executing...");

104Thread.sleep(1000);

105System.out.println("error occurs:" + new Date());

106throw new RuntimeException("something wrong");

107} catch (InterruptedException e) {

108}

109}

110

Java代码

112package com.ljn.timer;

113

114import java.util.Date;

115import java.util.TimerTask;

116

117

118public class OKT ask extends TimerTask {

119

120@Override

121public void run() {

122System.out.println("OKT ask is executed:" + new Date()); 123}

124}

Java代码

125package com.ljn.timer;

126

127import org.joda.time.DateTime;

128

129/**

130* @author lijinnan

131* @date:2013-11-25 下午5:17:40

132*/

133public class Helper {

134

135private Helper() {}

136

137public static final long ONE_DAY = 60 * 60 * 24;

138

139public static long calcDelay(int hour, int minute, int second) {

140if (!(0 <= hour && hour <=23 && 0 <= minute && minute <=59 && 0 <=second && second <= 59)) {

141throw new IllegalArgumentException();

142}

143return calcDelay(fixed(hour, minute, second));

144}

145

146private static long calcDelay(DateTime targetDatetimeOfToday) { 147long delay = 0;

148DateTime now = new DateTime();

149

150//时间点已过,只好延时到明天的这个时间点再执行

151if (now.isAfter(targetDatetimeOfToday)) {

152delay = now.plusDays(1).getMillis() - now.getMillis();

153

154//时间点未到

155} else {

156delay = targetDatetimeOfToday.getMillis() - now.getMillis(); 157}

158

159return delay;

160}

161

162/**

163* 返回这样一个DateTime对象:

164* 1.日期为今天

165* 2.时分秒为参数指定的值

166* @param hour 0-23

167* @param minute 0-59

168* @param second 0-59

169* @return

170*/

171private static DateTime fixed(int hour, int minute, int second) { 172

173return new DateTime()

174 .withHourOfDay(hour).withMinuteOfHour(minute).wit hSecondOfMinute(second);

175}

176

177}

(易错题精选)初中英语词汇辨析的单元汇编含答案解析

一、选择题 1.I’d like to________the mall because it’s crowded and noisy. A.visit B.hang out C.walk D.go off 2.That path ________ directly to my house.You won't miss it. A.leads B.forms C.repairs D.controls 3.I don’t want to go. __________, I am too tired. A.However B.And C.Besides D.But 4.Some animals carry seeds from one place to another, ________ plants can spread to new places. A.so B.or C.but D.for 5.When I as well as my cousins __________ as a volunteer in Beijing, I saw the Water Cube twice. A.were treated B.treated C.was served D.served 6.He is wearing his sunglasses to himself from the strong sunlight. A.prevent B.stop C.keep D.protect 7.When you are________, you should listen to music to cheer you up. A.shy B.afraid C.strict D.down 8.Mr. Smith gave us some________on how to improve our speaking skills. A.advice B.news C.knowledge D.information 9.World Book Day takes place ________ April 23rd every year. A.at B.in C.on 10.More and more people have realized that clear waters and green mountains are as ________ as mountain of gold and silver. A.central B.harmful C.valuable D.careful 11.We loved the food so much, ________the fish dishes. A.special B.especial C.specially D.especially 12.—Oh, my God! I have ________ five pounds after the Spring Festival. —All of the girls want to lose weight, but easier said than done. A.given up B.put on C.got on D.grown up 13.—What do you think of the performance today? —Great! ________ but a musical genius could perform so successfully. A.All B.None C.Anybody D.Everybody 14.He ________ his homework________the morning of Sunday. A.doesn’t do; on B.doesn’t do; in C.doesn’t; on 15.Maria ________ speaks Chinese because she doesn’t know much Chinese. A.seldom B.always C.often D.usually 16.In 2018, trade between China and Hungary rose by 7.5 percent, and recently on Friday companies from China and Hungary________ several cooperation (合作) agreements under the

https://www.sodocs.net/doc/4514809897.html, AJAX入门系列:Timer控件简单使用

https://www.sodocs.net/doc/4514809897.html, AJAX入门系列:Timer控件简单使用 本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下https://www.sodocs.net/doc/4514809897.html, AJAX中的服务端Timer控件的简单使用。 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计视图。 2.如果页面没有包含ScriptManager控件,在工具箱的AJAX Extensions标签下双击ScriptManager控件添加到页面中。 3.单击ScriptManager控件并双击UpdatePanel控件添加到页面中。

4.在UpdatePanel控件内单击并双击Timer控件添加到UpdatePanel中。Timer控件可以作为UpdatePanel的触发器不管是否在UpdatePanel中。 5.设置Interval属性为10000。Interval属性的单位是毫秒,所以我们设置为10000,相当于10秒钟刷新一次。 6.在UpdatePanel控件中添加一个Label控件。

7.设置Label控件的Text属性为“Panel not refreshed yet ”。确保Label控件添加在了UpdatePanel控件里面。 8.在UpdatePanel之外再添加一个Label控件。确保第二个Label控件在UpdatePanel的外面。 9.双击Timer控件添加Tick事件处理,在事件处理中设置Label1的Text属性为当前时间。 protected void Timer1_Tick(object sender, EventArgs e)

{ Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString(); } 10.在Page_Load事件中添加代码设置Label2的Text属性为页面创建时间,如下代码所示: protected void Page_Load(object sender, EventArgs e) { Label2.Text = "Page created at: " + DateTime.Now.ToLongTimeString(); } 11.切换到代码视图,确保代码如下所示: protected void Page_Load(object sender, EventArgs e) { Label2.Text = "Page created at: " + DateTime.Now.ToLongTimeString(); } protected void Timer1_Tick(object sender, EventArgs e) { Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString(); } 12.保存并按Ctrl + F5运行 13.等待10秒钟后可以看到Panel刷新,里面的Label文字改变为刷新的时间而外面的Label没有改变。

boring 令人厌烦的

boring 令人厌烦的,乏味的,无聊的 tedious 乏味的,单调的,冗长的 flat 单调的,沉闷的 dull 乏味的,单调的 troublesome 令人烦恼的,讨厌的,麻烦的 tired 疲劳的,累的 bored 无聊的,无趣的,烦人的 exhausted 极其疲倦的 weary 疲劳的 bright 聪敏的,机灵的 apt 聪明的,反应敏捷的 intelligent 聪明的,有才智的 shrewd 机灵的,敏锐的,精明的(表示生意上的精明) ingenious (人,头脑)灵巧的 alert 警觉的,留神的 cute 聪明伶俐的,精明的 acute/cute acute 指的是视力,感觉的敏锐 dull 愚钝的,笨的 awkward 笨拙的,不灵巧的 absurd 荒谬的 ridiculous 可笑的,荒谬的 idiotic 白痴般的 blunt 率直的,直言不讳的 clumsy 笨拙的,粗陋的 happy 快乐的,幸福的 cheerful 欢乐的,高兴的 content 满意的,满足的 merry 欢乐的,愉快的,快乐的 pleasure 高兴,愉快,满足 enjoyment 享乐,快乐,乐趣 cheer 喝彩 applause 鼓掌,掌声 optimism 乐观,乐观主义 delight 快乐,高兴 kick 极大的乐趣 paradise 天堂,乐园 instant 立即的,即刻的 instantaneous 瞬间的,即刻的 immediate 立即的,即刻的 simultaneous 同时发生的,同时存在的,同步的punctual 严守时刻的,准时的,正点的 pick 挑选,选择 select 选择,挑选 single 选出,挑出 elect 选举,推举 vote 投票,选举 appoint 任命,委派 nominate 提名,任命 propose 提名,推荐 recommend 推荐,举荐 designate 指派,委任 delegate 委派(或选举)…为代表 install(l) 使就职,任命 ballot 使投票表决 dub 把…称为 choice 选择(权) option 选择 selection 选择,挑选 alternative 取舍,供选择的东西 favorite 特别喜爱的人(或物) inclination 爱好 preference 喜爱,偏爱,优先 observe 注意到,察觉到 perceive 认识到,意识到,理解 detect 察觉,发现 appreciate (充分)意识到,领会,体会 alert 使认识到,使意识到 awake 意识到,醒,觉醒 scent 察觉 ancient 古代的,古老的 primitive 原始的 preliminary 预备的,初步的 preliminary trial初审 primary 最初的,初级的 initial 开始的,最初的 original 起初的 former 在前的,以前的 previous 先,前 prior 在前的,优先的 beforehand 预先,事先 medieval 中世纪的,中古(时代)的preceding 在先的,在前的,前面的 senior 资格较老的,地位较高的 following 接着的,下述的 attendant 伴随的 subsequent 随后的,后来的 succeeding 以后的,随后的 consequent 作为结果(或后果)的,随之发生的 resultant 作为结果的,因而发生的therefore 因此,所以 consequently 所以,因此 then 那么,因而 thus 因此,从而 hence 因此,所以 accordingly 因此,所以,于是 thereby 因此,从而

计时器控件在VB中的应用

计时器控件在VB中的应用 计时器控件在工具箱中的名称是Timer,该控件是一个非可视控件,即在运行时不可见,用于实现每隔一定时间间隔执行指定的操作。Timer控件对于其他后台处理也是非常有用的。本文用实例来介绍在VB程序中利用计时器控件,实现在程序在启动运行期间各种不同的效果。下面给出编程设计过程,供读者参考选用。 一、计时器(Timer)控件与标签(Label)控件的应用 1、启动VB,新建工程。在工程中添加一个窗体Form1,在窗体上加入一个Timer 计时器控件Timer1和标签控件Label1 2、编写相应的代码,实现不同的功能 (1)字体颜色发生随机变化的效果,计时器事件(Timer)代码如下: l 窗体Form1的加载事件代码 Private Sub Form_Load() Timer1.interval=500 Label1.Caption = “欢迎进入VB应用程序” Label1.font.size=20 Label1.autosize=true End Sub l 计时器(Timer1)控件的Timer事件代码 Private Sub Timer1_Timer() Label1.ForeColor = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd) End Sub (2)依次出现字幕的实现效果,相关事件代码如下: Dim i …在通用-声明中定义变量… Private Sub Timer1_Timer() i = i + 1 Label1.Caption = Left(“欢迎进入VB应用程序”, i) If i > 10 Then i = 0 End If End Sub (3)滚动字幕的实现效果,相关事件代码如下: l 窗体Form1的加载事件代码 Private Sub Form_Load() Label1.Caption = “欢迎进入VB应用程序” End Sub l 计时器(Timer1)控件的Timer事件代码 Private Sub Timer1_Timer() If Label1.Left <= Form1.Width Then Label1.Left = Label1.Left + 100 Else Label1.Left = -Label1.Width End If End Sub (4)制作字体闪烁的效果

boring 和bored的区别

不能片面说人做主语用ed,物做主语ing ing形式是修饰引起这种感觉的人或物;ed形式是描写人或物的感受。(当然物一般是动物) 翻译的话 ing形式的词译为“令人……的”;ed形式译为“……的” boring是令人感到厌烦的;bored是厌烦的。 a boring person 能够指一个了无情趣的人,让人觉得无趣的人 a bored person 则是说这个人自己感到很无趣 1.bore 1)vt.使厌烦;挖 e.g. I'm bored with this job. 这件工作厌烦了。 The oldier bore the sharp pain in the wound with great courage. 这士兵以巨大的勇气忍受着伤口的剧烈疼痛。 2)n.令人讨厌的人(或事) e.g. It's a bore having to go out again. 外出真是讨厌。 boredom n.厌倦,无趣 e.g. in infinite boredom 极其无趣 boring n. 钻(孔) adj. 令人厌烦的(事或物) e.g. The play was boring. 这部短剧很一点意思都没有。 bored adj. 无聊的, 无趣的, 烦人的 e.g. Jack is so bored. 杰克是个没有趣的人。 2.surprising 是针对事或物感到惊奇。 surprised 则是针对人。 3.pleasant adj. 愉快的, 快乐的, 舒适的, 合意的可爱的, 举止文雅的, 活泼的滑稽的, 有趣的 (天气)晴朗的, 美好的容易相处的, 友爱的 e.g. a pleasant voice 悦耳的声音 a pleasant companion 可爱的伴侣 a pleasant time 愉快地度过时光 pleasing adj. 舒适的, 使人愉快的; 满意的; 惹人喜欢的, 可爱的 e.g. a pleasing look 使人愉快的神情 a very well mannered and pleasing young man 彬彬有礼而令人喜爱的年轻人

iFix定时器控件使用心得

iFix定时器控件使用心得 iFix的定时器控件,经常会把初学者搞得头晕脑涨,我说说自己的心得,供大家参考。 该控件是基于调度功能的,所以有一些用法和其它编程平台(如VB)里的定时器不太一样。 一、定时器的启动/停止 如果在编辑时TimerEnabled设为True,则运行时定时器会自动启动。如果在编辑时TimerEnabled设为False,则运行时需要先将TimerEnabled设为True,然后调用StartTimer方法。如果只将TimerEnabled设为True,但是不调用StartTimer 方法,定时器是不会开始工作的。如果要停止定时器,可以调用StopTimer方法,也可以直接将TimerEnabled设为False。也就是说有两种控制定时器启/停的方式: 方式一: 用如下代码启动:Timer1. TimerEnabled=True Timer1. StartTimer 用如下代码停止:Timer1. TimerEnabled=False 方式2: 在画面或调度的Initializes事件中加入:Timer1. TimerEnabled=True 用如下代码启动:Timer1. StartTimer 用如下代码停止:Timer1. StopTimer 二、以“连续”方式使用 以“连续”方式使用时,你会发现这样的现象,例如你希望一个画面被打开10秒钟后自动关闭,你会将定时器的Interval 属性设为10000,事实上却是,画面不到10秒就会被关闭,而且每次的延时时间还不是固定的,似乎是随机的,有时几乎是10秒,有时还不到1秒。这个举例中,定时器仅运行了1次(因为画面已经被关闭了),如果定时器一直运行下去,你还会发现,除了第一次的延时是“随机”的,从第二次开始,延时都是准确的。 这究竟是怎么回事呢?其实这是StartTime属性在起作用,StartTime属性的默认值是0:00:00,表示从午夜0点0分0秒开始,在这种情况下,如果设置为10秒钟的间隔,定时器被触发的时间将是每一分钟的0秒、10秒、20秒……50秒,如果从某一分钟的18秒启动了定时器,那么定时器第一次被触发的时间将会是20秒,也就是说,从启动到第一次触发之间仅有2秒钟的延时,如果你从15秒启动,会得到5秒钟的延时,这就是为什么你会觉得第一次的延时是“随机”的。 好的,既然知道了原因,自然也就有了解决的方法,那就是在每一次调用StartTimer方法之前,将StartTime属性设为当前时间,即Timer1. StartTime = Now就搞定了。例如在8:15:23秒启动,间隔10秒,第一次触发将会是在8:15:33秒的时候。 那是不是所有以“连续”方式使用时,这样作就都OK了呢?不是。这个方法是否有效(也就是得到精确的延时),要看你所希望的延时时间有多长,如果延时是10秒或更长,那没问题,这样是唯一正确且简便的方法。但如果你设置的延时间隔比较小,如3秒以内,甚至是毫秒级的,那么这个方法就会产生比较严重的误差。因为StartTime属性的时间精度只达到秒级,也就是说,实际的运行效果还是会有一定的误差,当然,这个误差最大不会超过1秒,所以一般来说对于5秒以上的延时设置,这个误差可以忽略。但如果延时设置是2秒,然后产生了接近1秒的误差,这就成问题了,误差率将近50%啊!如何解决此类问题呢?有办法,只是稍复杂一点。 例如,我们希望做到这样一个效果——有一个按钮对象(名为cmd1),当用鼠标点击这个按钮时,按钮消失不见,2秒钟之后又出现。也就是说在点击的时候把按钮的Visible属性设为False,并且启动一个定时器控件,2秒之后在定时器的OnTimeOut事件代码中,再把cmd1的Visible属性设为True。 如何比较精确地实现这2秒的时间间隔呢?具体做法是:将定时器的Interval属性设为100毫秒,定义一个模块级变

(易错题精选)初中英语词汇辨析的难题汇编及解析

一、选择题 1.Is this a photo of your son? He looks________ in the blue T-shirt. A.lovely B.quietly C.beautiful D.happily 2.—Jerry looks so tired. He works too hard. —He has to ________ a family of four on his own. A.offer B.support C.provide D.remain 3.— Mr. Wilson, can I ask you some questions about your speech? — Certainly, feel __________ to ask me. A.good B.patient C.free D.happy 4.Some animals carry seeds from one place to another, ________ plants can spread to new places. A.so B.or C.but D.for 5.— Can you tell us about our new teacher? —Oh, I’m sorry. I know________ about him because I haven’t seen him before. A.something B.anything C.nothing D.everything 6.—Help yourselves! The drinks are ________ me. —Thank you. You’re always so generous. A.above B.in C.on D.over 7.Gina didn’t study medicine. ________, she decided to become an actor. A.Instead B.Again C.Anyway D.Also 8.—Have you got Kathy’s________ for her concert? —Yes, I’d like to go and enjoy it. A.interview B.information C.invitation D.introduction 9.More and more people have realized that clear waters and green mountains are as ________ as mountain of gold and silver. A.central B.harmful C.valuable D.careful 10.Kangkang usually does her homework ________ it is very late at night. A.until B.when C.before D.after 11.He ________all the “No Smoking” signs and lit up a cigarette. A.requested B.attacked C.protected D.ignored 12.一Where is Mr. Brown? 一I think he's _____________ the music hall. A.on B.in C.over D.from 13.— Is your home close to the school, Tom? — No, it's a long way, but I am________ late for school because I get up early daily. A.always B.usually C.never D.sometimes 14.—Mum, I don’t want the trousers. They’re too long.

c_中timer控件的使用

C#中Timer组件用法 Timer组件是也是一个WinForm组件了,和其他的WinForm组件的最大区别 是:Timer组件是不可见的,而其他大部分的组件都是都是可见的,可以设计的。Timer组件也被封装在名称空间System.Windows.Forms中,其主要作用是当Timer组件启动后,每隔一个固定时间段,触发相同的事件。Timer组件在程序设计中是一个比较常用的组件,虽然属性、事件都很少,但在有些地方使用它会产生意想不到的效果。 其实要使得程序的窗体飘动起来,其实思路是比较简单的。首先是当加载窗体的时候,给窗体设定一个显示的初始位置。然后通过在窗体中定义的二个Timer组件,其中一个叫Timer1,其作用是控制窗体从左往右飘动(当然如果你愿意,你也可以改为从上往下飘动,或者其他的飘动方式。),另外一个Timer2是控制窗体从右往左飘动(同样你也可以改为其他飘动方式)。当然这二个Timer 组件不能同时启动,在本文的程序中,是先设定Timer1组件启动的,当此Timer1启动后,每隔0.01秒,都会在触发的事件中给窗体的左上角的横坐标都加上"1",这时我们看到的结果是窗体从左往右不断移动,当移动到一定的位置后,Timer1停止。Timer2启动,每隔0.01秒,在触发定义的事件中给窗体的左上角的横坐标都减去"1",这时我们看到的结果是窗体从右往左不断移动。当移动到一定位置后,Timer1启动,Timer2停止,如此反覆,这样窗体也就飘动起来了。要实现上述思路,必须解决好以下问题。 (1).如何设定窗体的初始位置: 设定窗体的初始位置,是在事件Form1_Load()中进行的。此事件是当窗体加载的时候触发的。Form有一个DesktopLocation属性,这个属性是设定窗体的左上角的二维位置。在程序中是通过Point结构变量来设定此属性的值,具体如下: //设定窗体起初飘动的位置,位置为屏幕的坐标的(0,240) private void Form1_Load ( object sender , System.EventArgs e ) { Point p = new Point ( 0 , 240 ) ; this.DesktopLocation = p ; } (2). 如何实现窗体从左往右飘动: 设定Timer1的Interval值为"10",就是当Timer1启动后,每隔0.01秒触发的事件是Timer1_Tick(),在这个事件中编写给窗体左上角的横坐标不断加"1"的代码,就可以了,具体如下:

【英语】英语形容词常见题型及答题技巧及练习题(含答案)及解析

【英语】英语形容词常见题型及答题技巧及练习题(含答案)及解析 一、初中英语形容词 1.My deskmate is really _____.She likes to attend different activities after school. A. active B. quiet C. lazy D. honest 【答案】 A 【解析】【分析】我的同桌同学非常活跃,放学后喜欢参加很多不同的活动. 句中提到"She likes to attend different activities after school"放学后喜欢参加很多不同的活动,由此推测此人非常活跃,A积极的,活跃的;B安静的;C懒惰的,D诚实的,根据句意可知选择A. 2.Wang Wei speaks English as ________ as Yang Lan. They both study English hard. A. good B. well C. better D. best 【答案】 B 【解析】【分析】句意:王伟的英语讲的和杨澜的一样好。他们学习英语都努力。可知as…as中间用形容词或副词原级;此处是副词修饰动词speak。good好的,形容词原形;well好地,副词原形,better比较级;best最高级,故选B。 【点评】此题考查形容词原级。注意as...as中间跟形容词或副词原级。 3.—If there are ________ people driving, there will be ________ air pollution. —Yes, and the air will be fresher. A. less; less B. less; fewer C. fewer; fewer D. fewer; less 【答案】 D 【解析】【分析】句意:——如果开车的人越少,空气污染越少。——是的,空气将会更新鲜。little少的,形容词,其比较级是less,修饰不可数名词,few几乎没有,形容词,其比较级是fewer,更少,修饰可数名词,people,可数名词,用fewer修饰,air pollution,空气污染,不可数名词,用less修饰,故选D。 【点评】考查形容词的辨析。注意less和fewer意思和用法。 4.—Guess what? The university has accepted my application! —Wow! That's ________ new I've heard this year, Boris! Let's celebrate. A. a worse B. the worst C. a better D. the best 【答案】 D 【解析】【分析】句意:——猜猜什么?那所大学已经接受我的申请了。——哇喔,那是今年我听到的最好的消息,Boris,让我们庆祝一下。A.一个更糟的,比较级;B.最糟的,最高级;C.一个更好的,比较级;D.最好的,最高级。因为大学接受申请了,所以是好消息,排除A、B。根据 I've heard this year,今年我听到的,可知是最高级,故选D。 【点评】考查形容词辨析,注意平时识记最高级结构,理解句意。

使用C#的Timer控件来实现定时触发事件

使用C#的Timer控件来实现定时触发事件 C# Timer用法有哪些呢?我们在使用C# Timer时都会有自己的一些总结,那么这里向你介绍3种方法,希望对你了解和学习C# Timer使用的方法有所帮助。 关于C# Timer类在C#里关于定时器类就有3个 C# Timer使用的方法1.定义在System.Windows.Forms里 C# Timer使用的方法2.定义在System.Threading.Timer类里" C# Timer使用的方法3.定义在System.Timers.Timer类里 下面我们来具体看看这3种C# Timer用法的解释: ◆System.Windows.Forms.Timer 应用于WinForm中的,它是通过Windows消息机制实现的,类似于VB或Delphi中的Timer 控件,内部使用API SetTimer实现的。它的主要缺点是计时不精确,而且必须有消息循环,Console Application(控制台应用程序)无法使用。 ◆System.Timers.Timer 和System.Threading.Timer非常类似,它们是通过.NET Thread Pool实现的,轻量,计时精确,对应用程序、消息没有特别的要求。 ◆System.Timers.Timer还可以应用于WinForm,完全取代上面的Timer控件。它们的缺点是不支持直接的拖放,需要手工编码。 C# Timer用法实例 使用System.Timers.Timer类 System.Timers.Timer t = new System.Timers.Timer(10000); //实例化Timer类,设置间隔时间为10000毫秒; t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件; t.AutoReset = true; //设置是执行一次(false)还是一直执行(true); t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; public void theout( object source, System.Timers.ElapsedEventArgs e) { MessageBox.Show("OK!"); } C# Timer用法的基本情况就向你介绍到这里,希望对你了解和学习C# Timer使用有所帮助。详细参考:https://www.sodocs.net/doc/4514809897.html,/zh-cn/library/vstudio/system.timers.timer.aspx

(易错题精选)初中英语词汇辨析的知识点训练附答案(1)

一、选择题 1.He wrote his phone number ________ a piece paper. A.on B.for C.in D.from 2.Many people think Erquan rngyue is too sad, _____________ it's my favorite. A.and B.so C.or D.but 3.That path ________ directly to my house.You won't miss it. A.leads B.forms C.repairs D.controls 4.Some animals carry seeds from one place to another, ________ plants can spread to new places. A.so B.or C.but D.for 5.When I as well as my cousins __________ as a volunteer in Beijing, I saw the Water Cube twice. A.were treated B.treated C.was served D.served 6.—The 30 firefighters’ brave action ________ their lives in the forest fire on March30, 2019.—The people of Muli County will never forget them. A.took B.cost C.save D.solve 7.Gina didn’t study medicine. ________, she deci ded to become an actor. A.Instead B.Again C.Anyway D.Also 8.—Have you got Kathy’s________ for her concert? —Yes, I’d like to go and enjoy it. A.interview B.information C.invitation D.introduction 9.We should learn_______ each other. A.to B.from C.for D.of 10.World Book Day takes place ________ April 23rd every year. A.at B.in C.on 11.Kangkang gets up early every day and he is ________ late for school. A.sometimes B.often C.never D.usually 12.It’s ________ of the soldiers to rush into the fire to save peo ple. A.stupid B.proud C.honest D.brave 13.—Do you know what the meeting is about? —Yes, of course. It will ________ some important rules we need to know about our new senior high school. A.talk B.achieve C.memorize D.cover 14.Mary doesn’t like hamburgers________meat. She doesn’t want to be fat. A.or B.and C.but 15.I’d like to________the mall because it’s crowded and noisy. A.visit B.hang out C.walk D.go off

vb6.0时间控件timer详解

vb6.0时间控件timer详解 通过引发Timer 事件,Timer 控件可以有规律地隔一段时间执行一次代码。 语法 Timer 说明 Timer 控件用于背景进程中,它是不可见的 ************************以下是他的属性**************** Enabled 属性 返回或设置一个值,该值用来确定一个窗体或控件是否能够对用户产生的事件作出反应。 语法 object.Enabled [= boolean] Enabled 属性的语法包含下面部分: 部分描述 object 对象表达式,其值是“应用于”列表中的一个对象。如果object 被省略,则与活动窗体模块相联系的窗体被认为是object。 boolean 一个用来指定object 是否能够对用户产生的事件作出反应的布尔表达式。 设置 boolean 的设置为: 设置描述 True (缺省)允许object 对事件作出反应。 False 阻止object 对事件作出反应。 Enabled 属性示例 该例子使一个CommandButton 控件有效而不管TextBox 控件是否包含文本。要试用此例,先将下面的代码粘贴到带有CommandButton 和TextBox 控件的一个窗体的声明部分,然后按下F5 键并在文本框中随意输入一些内容。 Private Sub Form_Load () Text1.Text = "" ' 清除文本框的内容。

Command1.Caption = "Save" ' 在按钮上放置标题。 End Sub Private Sub Text1_Change () If Text1.Text = "" Then '查看文本框是否为空。 Command1.Enabled = False '使按钮无效。 Else Command1.Enabled = True '使按钮有效。 End If End Sub Interval 属性 返回或设置对Timer 控件的计时事件各调用间的毫秒数。 语法 object.Interval [= milliseconds] Interval 属性语法有以下组成部分: 部分描述 object 对象表达式,其值是“应用于”列表中的一个对象。 milliseconds 数值表达式,指定毫秒数,“设置值”中有详细说明,。 设置值 milliseconds 的设置值为: 设置值描述 0 (缺省值)使Timer 控件无效。 1 to 65,535 设置的时间间隔(以毫秒计),在Timer 控件Enabled 属性设置为True 时开始有效,例如,10,000 毫秒等于10 秒。最大值为65,535 毫秒,等于1 分钟多一些。 说明 可以在设计时或在运行时设置Timer 控件的Interval 属性。使用Interval 属性时,请记住: Timer 控件的Enabled 属性决定该控件是否对时间的推移做响应。将Enabled 设置为False 会关闭Timer 控件,设置为True 则打开它。当Timer 控件置为有效时,倒计时总是从其Interval 属性的设置值开始。 创建Timer 事件程序用以告诉Visual Basic 在每次Interval 到时该做什么。 Interval 属性示例

(易错题精选)初中英语词汇辨析的知识点总复习有答案解析(1)

一、选择题 1.The next Olympic Games will be held in Japan________ 27th July 2020. A.on B.in C.at D.of 2.Many people think Erquan rngyue is too sad, _____________ it's my favorite. A.and B.so C.or D.but 3.—Oh, my God! I have ________ five pounds after the Spring Festival. —All of the girls want to lose weight, but easier said than done. A.given up B.put on C.got on D.grown up 4.I don’t want to go. __________, I am too tired. A.However B.And C.Besides D.But 5.— Mr. Wilson, can I ask you some questions about your speech? — Certainly, feel __________ to ask me. A.good B.patient C.free D.happy 6.People who always do sports are in spirits than those who don't. A.high B.higher C.tall D.taller 7.When I as well as my cousins __________ as a volunteer in Beijing, I saw the Water Cube twice. A.were treated B.treated C.was served D.served 8.—Help yourselves! The drinks are ________ me. —Thank you. You’re always so generous. A.above B.in C.on D.over 9.—The 30 firefighters’ brave action ________ their lives in the fores t fire on March30, 2019.—The people of Muli County will never forget them. A.took B.cost C.save D.solve 10.—Have you got Kathy’s________ for her concert? —Yes, I’d like to go and enjoy it. A.interview B.information C.invitation D.introduction 11.These oranges looks nice, but _____ very sour. A.taste B.smell C.sound D.look 12.We’d better finish our work ________ one go. Don’t put it off till next time. A.in B.to C.on D.for 13.We loved the food so much, ________the fish dishes. A.special B.especial C.specially D.especially 14.He ________ his homework________the morning of Sunday. A.doesn’t do; on B.doesn’t do; in C.doesn’t; on 15.—Dad, what is the loudspeaker saying? —It is to the . The flight to Wuhan is boarding now. A.customers B.passengers C.members D.tourists

相关主题