有这样 一段 程序:
     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 方法 使用 必须 的 还是 有 别的 作用

解决方案 »

  1.   

    当你过程里面有调用本线程的控件的时候.如果是非当前线程,就用委托.如果是当前线程,则可以直接调用控件..不然就会出错.跨线程调用控件就是这样.
      

  2.   

    以上 这个函数 是 由一个 计算机的 系统事件 触发的 是一个 本地计算机 有 新条目 加入的事件。 是不是 就是 这个 原因 导致 需要 检查 。 那 还有没有 别的 情况 会出现 调用线程 和 创建线程 不一致呢?