timeSetEvent的迷惑啊。高手请进啊。急急

fxj31 2007-04-03 04:52:55
基本程序如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim temp As New ipfunctionback(AddressOf TimeProc)
lTimeID = timeSetEvent(1000, 1, temp, 1, 1)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call EndCount()
End Sub
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Integer, ByVal uResolution As Integer, ByVal lpFunction As ipfunctionback, ByVal dwUser As Integer, ByVal uFlags As Integer) As Integer
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Integer) As Integer
Public Delegate Sub ipfunctionback(ByVal uID As Integer, ByVal uMsg As Integer, ByVal dwUser As Integer, ByVal dw1 As Integer, ByVal dw2 As Integer)
Public lmmCount As Integer
Public lTimeID As Integer

Sub temp1()
Dim temp As New ipfunctionback(AddressOf TimeProc)
lTimeID = timeSetEvent(1000, 1, temp, 1, 1)
End Sub
Sub TimeProc(ByVal uID As Integer, ByVal uMsg As Integer, ByVal dwUser As Integer, ByVal dw1 As Integer, ByVal dw2 As Integer)
lmmCount = lmmCount + 1
Me.Label1.Text = CStr(lmmCount)
End Sub

Sub EndCount()
timeKillEvent(lTimeID)
End Sub
现运行时有奇怪问题:
直接运行时timeSetEvent回调了几次TimeProc出错信息为(未处理的“System.NullReferenceException”类型的异常出现在 未知模块 中。)
但如果我在出错前点击下button2(也就是执行下Sub EndCount())再运行button1_chick就没有问题。
这到底是怎么回事。小弟新手不明白啊
...全文
646 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tl_pear 2007-04-04
  • 打赏
  • 举报
回复
呵呵,兄弟,我测试了下,一切正常呀!
没有出现System.NullReferenceException错误
fxj31 2007-04-03
  • 打赏
  • 举报
回复
问题肯定是出在
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim temp As New ipfunctionback(AddressOf TimeProc)
lTimeID = timeSetEvent(1000, 1, temp, 1, 1)
End Sub
那个temp委托指针上把它改成静态不会出错。但为什么我没改前运行下Sub EndCount()就能正常运行呢。实在不解啊。
Red_angelX 2007-04-03
  • 打赏
  • 举报
回复
帮顶

16,557

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧