有这样 一段 程序:
Private Delegate Sub d_appendEntryToDataSet(ByVal [message] As String, _
ByVal [source] As String, _
ByVal [type] As
System.Diagnostics.EventLogEntryType, _
ByVal [instanceID] As Long, _
ByVal [category] As String)
ByVal [category] As String)
Private Sub evLog_EntryWritten(ByVal sender As Object, ByVal e As System.Diagnostics.EntryWrittenEventArgs)
If Me.InvokeRequired Then
' Update the dataset by calling the delegate
Dim d As New d_appendEntryToDataSet(AddressOf appendEntryToDataSet)
Me.Invoke(d, New Object() {e.Entry.Message, e.Entry.Source, e.Entry.EntryType, e.Entry.InstanceId, e.Entry.Category})
Else
' Update the underlying dataset as events from the event log seem to be unreliable
Me.appendEntryToDataSet(e.Entry.Message, e.Entry.Source, e.Entry.EntryType, e.Entry.InstanceId, e.Entry.Category)
End If
End Sub我就想 请教 什么 时候 需要 使用 InvokeRequired 来检查 调用 线程 和 创建线程 的 不同
在我 没 用 代码 添加的 情况下 为什么 会 出现 不同 我怎么 知道 什么 时候 可能 出现 这种 情况。
此处 代理 是 invoke 方法 使用 必须 的 还是 有 别的 作用
Private Delegate Sub d_appendEntryToDataSet(ByVal [message] As String, _
ByVal [source] As String, _
ByVal [type] As
System.Diagnostics.EventLogEntryType, _
ByVal [instanceID] As Long, _
ByVal [category] As String)
ByVal [category] As String)
Private Sub evLog_EntryWritten(ByVal sender As Object, ByVal e As System.Diagnostics.EntryWrittenEventArgs)
If Me.InvokeRequired Then
' Update the dataset by calling the delegate
Dim d As New d_appendEntryToDataSet(AddressOf appendEntryToDataSet)
Me.Invoke(d, New Object() {e.Entry.Message, e.Entry.Source, e.Entry.EntryType, e.Entry.InstanceId, e.Entry.Category})
Else
' Update the underlying dataset as events from the event log seem to be unreliable
Me.appendEntryToDataSet(e.Entry.Message, e.Entry.Source, e.Entry.EntryType, e.Entry.InstanceId, e.Entry.Category)
End If
End Sub我就想 请教 什么 时候 需要 使用 InvokeRequired 来检查 调用 线程 和 创建线程 的 不同
在我 没 用 代码 添加的 情况下 为什么 会 出现 不同 我怎么 知道 什么 时候 可能 出现 这种 情况。
此处 代理 是 invoke 方法 使用 必须 的 还是 有 别的 作用
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货