我怎样才能避免穿越线程...... [英] How can I avoid crossing the threads...

查看:80
本文介绍了我怎样才能避免穿越线程......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在与VB的战斗中,我对被测单元没有可靠的可靠通信。

我可以得到它回复一个富文本框,我怎么想得到完整的回复

如果我在下面的函数中监视它

Hi All,

In my battle with VB I have no got solid reliable comms with the Unit Under Test.
I can get it to reply to a rich text box, how ever I want to get the complete reply
If I monitor it in the below function

Private Sub port_DataReceived_ATE(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)

        TmrNoDataAtPortATE.Enabled = False
        InputData = ATEComPort.ReadExisting
        Reply_Status = REPLY_ATE.YES_REPLY

        If InputData <> [String].Empty Then
            Me.BeginInvoke(New SetTextCallbackATE(AddressOf SetTextATE), New Object() {InputData})
            'MsgBox("here!")
        Else
            MsgBox("null")
        End If
        TmrNoDataAtPortATE.Enabled = False
        If (Reply_Status = REPLY_ATE.TIMEOUT_REPLY) Then
            Data_Back = "TIMEOUT"
        ElseIf (Reply_Status = REPLY_ATE.YES_REPLY) Then
            TmrNoDataAtPortATE.Enabled = False

        End If
        'Me.Invoke(Me.rtbIncomingATE.Text)

    End Sub



和更改调用的函数是


and change invoked function is

Private Sub SetTextATE(ByVal textATE As String)

      ' If (textATE = Chr(13)) Then MsgBox(rtbIncomingATE.Text) works once
      Me.rtbIncomingATE.Text += textATE

      'in here use an if or switch (Select) to sort out what goes where

  End Sub



if()语句用于捕获单元具有的Cr,因为结尾似乎只能工作一次,

我正在交谈的董事会在每次回复后都会产生回车。我希望做的是监视一个Chr(13)的textATE,当遇到一个,这意味着答复终止,所以我可以去处理它。最糟糕的是它似乎工作一次但只有一次。是否有正确的方法在主GUI线程上获取rtb的内容?



Glenn,我认为这可能与BeginInvoke切换到Invoke有关。 ..和测试!


the if() statement to catch the Cr that the unit has as the end only seems to work once,
the board I am talking to does produce a carriage return after each reply. What I was hoping to do was to monitor textATE for a Chr(13) when one was encountered that means the reply is terminated so I could go and process it. The worst thing is it appears to work once but only once. Is there a correct method of getting the contents of the rtb on the main GUI thread?

Glenn, I think it might be something to do with BeginInvoke switching to Invoke... and testing!

推荐答案

而不是

Instead of
Me.BeginInvoke(New SetTextCallbackATE(AddressOf SetTextATE), New Object() {InputData})





为什么不按如下方式调用SetTextATE:



Why don't you just call SetTextATE as follows:

Call SetTextATE(InputData)


我一起攻击了一个解决方案,允许我在下面继续:



I have hacked a solution together to allow me to proceed below:

Private Sub btnRE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRE.Click

       rtbIncomingATE.Text = ""
       TmrNoDataAtPortATE.Enabled = True
       Reply_Status = REPLY_ATE.NO_REPLY
       Write_HyperTerm_Style("#RE" & Chr(13)) 'sends RE command
       While (rtbIncomingATE.Text.Length < 5)
           Application.DoEvents()
       End While
       Call btnBodge_Click(sender, e)
       rtbIncomingATE.Text = ""


   End Sub





我有一个单独的点击例程来从中获取数据:



And I had a separate click routine to get the data from it:

Public Sub btnBodge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBodge.Click
    Dim StringReply, StringReplyA As String

    StringReply = rtbIncomingATE.Text
    ' MsgBox(StringReply)
    StringReplyA = StringReply.Substring(0, 5)
    txtREresponce.Text = StringReplyA
    'MsgBox(StringReplyA)
    rtbIncomingATE.Clear()

End Sub



这是令人讨厌的,但它让我超过了一个驼峰,此刻这是主要的事情!


It's nasty but it gets me over a hump, at the moment that is the main thing!


这篇关于我怎样才能避免穿越线程......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆