为什么主界面会没有响应啊

xrbeck 2005-09-09 03:40:53
程序是这样的:
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mn_NotesStart.Click
Dim oConfig As New SMSClass.CConfig
Dim iInterval As Integer

oConfig.ConfigFile = "SMSCenter.exe.config"
mNotes.ServerName = oConfig.GetKeyValue("Notes_ServerName")
mNotes.DBName = oConfig.GetKeyValue("Notes_DBName")

Try
iInterval = CType(oConfig.GetKeyValue("Notes_ScanInterval"), Integer)
Catch ex As Exception
MsgBox("Notes 扫描时间不正确,请重新设置!", MsgBoxStyle.Exclamation)
Exit Sub
End Try

If mNotes.Init() Then
mn_NotesStart.Enabled = False
mn_NotesStop.Enabled = True

'开新的Notes发送线程
NotesThread = New System.Threading.Thread(AddressOf mNotes.NotesProc)
NotesThread.IsBackground = True
NotesThread.Start()

mbStartNotes = True '表示启用Notes服务,Timer2_Tick 中使用

Timer2.Interval = iInterval * 1000
Timer2.Start()

MsgBox("Notes短信服务已经启动!", MsgBoxStyle.Information)

Else
MsgBox("无法启动Notes短信服务,请检查Notes的环境配置!", MsgBoxStyle.Exclamation)
End If

End Sub

Private Sub mn_NotesStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mn_NotesStop.Click

Timer2.Stop()

mbStartNotes = False '服务停止

If mNotes.UnInit() Then
mn_NotesStart.Enabled = True
mn_NotesStop.Enabled = False

MsgBox("Notes短信服务已经停止!", MsgBoxStyle.Information)
Else
MsgBox("终止Notes短信服务出现错误!", MsgBoxStyle.Exclamation)
End If

End Sub
按钮触发这个函数后,主界面就没响应了

timer(定时器)是这样的:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Not mbStartNotes Then
Exit Sub
End If

Timer2.Stop()

If (NotesThread.ThreadState = Threading.ThreadState.Stopped) Then '如果线程执行完毕则激活新的Notes发送线程
NotesThread = Nothing
NotesThread = New System.Threading.Thread(AddressOf mNotes.NotesProc)
NotesThread.IsBackground = True

NotesThread.Start()
End If

If (NotesThread.ThreadState = Threading.ThreadState.Suspended) Then '如果已挂起则唤醒
NotesThread.Resume()
End If
Timer2.Start()

End Sub
...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xrbeck 2005-09-09
  • 打赏
  • 举报
回复
是不是线程间有什么冲突?
.NET一般什么原因会引起一个线程影响到另一个线程啊?
请大侠们指教小弟

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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