您的位置:程序门 -> vb -> 资源



vb高手帮帮忙啊!!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb高手帮帮忙啊!!![已结贴,结贴人:hanxinglian]
发表于:2007-09-13 16:29:29 楼主
用timegettime函数定时50ms,在50ms内计时,按时间逐行查数据库记录,再调用厂家提供的dll函数输出给硬件。处理时间超过了50ms,造成定时器被拖后,4分钟的任务花了8分钟。
现在提出采用多线程的办法,把硬件输出函数放到一个线程中执行,不知怎么样???
大家说说。
发表于:2007-09-13 17:00:411楼 得分:20
下面的代码用计时代替定时,这样即使用   debug.print   模拟的一次操作超过   50ms,下次操作会马上触发而不用再等   50ms。

option   explicit

private   declare   function   queryperformancecounter   lib   "kernel32 "   (lpperformancecount   as   any)   as   long
private   declare   function   queryperformancefrequency   lib   "kernel32 "   (lpfrequency   as   any)   as   long

private   start   as   currency
private   frequency   as   currency

sub   main()
        dim   nextms   as   long
        dim   currentms   as   long
       
        queryperformancefrequency   frequency
        queryperformancecounter   start
       
        nextms   =   50
        while   nextms   <=   1000
                currentms   =   getmillisecond
                if   currentms   <   nextms   then
                        doevents
                else
                        debug.print   "timer   at   "   &   currentms   &   "   ms "
                        nextms   =   nextms   +   50
                end   if
        wend
end   sub

function   getmillisecond()   as   long
        dim   current   as   currency
        queryperformancecounter   current
        getmillisecond   =   ((current   -   start)   /   frequency)   *   1000
end   function
发表于:2007-09-13 19:31:392楼 得分:0
谢谢了,马上试一下.
发表于:2007-09-13 19:40:253楼 得分:0
现在问题是50ms内根本执行不完程序,提前结束没有意义.如果将任务分成几个线程并行执行,能不能在50ms内全部完成.


快速检索

最新资讯
热门点击