miaoichi 發表於 2010-9-13 00:14:45

Roboard + XPE 跑thread會當

最近用xpe跑我寫的vb.net,裡面跑一個thread然後就會當機~~~
不知有沒有解?


    Private engineThread As Thread
    Private Sub RunIKEngine()
      Dim a As Long = 0
      Do While True
            a += 1
            SetLabel4(a.ToString)
      Loop
    End Sub

    Private Sub StartThread()
      'Create a thread that will the RunHexEngine method in the background.
      engineThread = New Thread(AddressOf RunIKEngine)
      engineThread.IsBackground = True
      engineThread.Start()
    End Sub

mzw2008 發表於 2010-9-13 12:15:26

roboard是不會因為執行緒當機的
那個setLabel4內容是長怎樣?!< ----我覺得問題出在這裡
執行緒通常別牽拖UI
硬要做得有別的辦法

miaoichi 發表於 2010-9-14 09:24:28

    Delegate Sub SetTextBox1Callback(ByVal As String)
    Private Sub SetLabel4(ByVal As String)
      If Me.Label4.InvokeRequired Then
            Dim del As New SetTextBox1Callback(AddressOf SetLabel4)
            Me.Invoke(del, New Object() {})
      Else
            Me.Label4.Text =
      End If
    End Sub

mzw2008 發表於 2010-9-14 13:55:38

最好別這樣作
invoke號稱可以搞定UI
但還是會有別的狀況
通常我執行緒就是單純運算或是監視

要動UI用timer + 全域變數 最安全

另外 這種寫法是翻譯器亂翻的
別使用這樣的東西
建議改成"str" 或是"字串" 之類的變數名稱, 程式會比較簡潔易懂

miaoichi 發表於 2010-9-16 07:54:04

謝謝m大,那我再試試看吧~~謝謝
頁: [1]
查看完整版本: Roboard + XPE 跑thread會當