首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

急线程委托有关问题,请大侠指点

2012-02-09 
急:线程委托问题,请大侠指点。Imports System.Data.SqlClientPublic Class ggbfPublic temp As String

急:线程委托问题,请大侠指点。
Imports System.Data.SqlClient
Public Class ggbf
  Public temp As String = ""
  Delegate Sub setG(ByVal i As Integer)
  Dim xc As New System.Threading.Thread(AddressOf displayG)’播放图片线程
  Dim receiveing As New System.Threading.Thread(AddressOf setreceive)‘收取网络数据线程
  Delegate Sub setcloses(ByVal x1 As Form, ByVal y1 As Boolean)
  <Runtime.InteropServices.DllImport("DllTest.dll")> _
Shared Function receive() As String‘DLL里的线程,用来收取网络发来的数据
  End Function
  <Runtime.InteropServices.DllImport("DllTest.dll")> _
  Shared Sub sendTo(ByVal x As String)‘用来发送数据
  End Sub
  <Runtime.InteropServices.DllImport("DllTest.dll")> _
  Shared Sub clean()
  End Sub
  <Runtime.InteropServices.DllImport("DllTest.dll")> _
  Shared Sub quit()
  End Sub
  <Runtime.InteropServices.DllImport("DllTest.dll")> _
 Shared Sub start()'初始化网络端口
  End Sub
  Private Sub ggbf_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Me.Location = New Point(0, 0)
  My.Forms.cljg.Show()
  xc.Start()
  start()
  receiveing.Start()
  End Sub
  Public Sub displayG(ByVal x As Integer)
  setxc("select * from [guanggao] Order By u_id ")
  If settable.Rows.Count = 0 Then
  MsgBox("无广告内容!")
  Else
  For i As Integer = 0 To settable.Rows.Count - 1
  If i = settable.Rows.Count - 1 Then
  i = 0
  End If
  readbytephoto(settable.Rows(i).Item("u_tp"), Picture)
  System.Threading.Thread.Sleep(5000) '延时一秒
  Next i
  End If
  End Sub
  Sub setreceive()
  Dim a As Boolean = True
  While a
  Dim str As String = receive()‘收网络数据,如果没有数据,这个线程会卡在那。
  System.Threading.Thread.Sleep(10)
  str = Mid(str, 1, 5)
  If str = "hello" Then
  sendTo("hello")
  End If
  Select Case Mid(str, 2, 1)
  Case "#"
  sendTo("^#OK" & vbCr)
  a = False
  setclose(My.Forms.Form6, True)
  End Select
  End While
  End Sub
  Private Sub setclose(ByVal x As Form, ByVal y As Boolean)
  If x.InvokeRequired Then
  Dim d As New setcloses(AddressOf setclose)
  Me.Invoke(d, New Object() {x, y})
  Else
  If y Then
  x.Show()
  Else
  x.Close()
  End If
  End If
  End Sub
  Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
  xc = Nothing
  receiveing = Nothing
  End Sub
End Class
执行CASE #时为什么不能完成打开一个新窗体并关闭me的操作呢,我改过了,也不行,不是打不开新窗体就是打开了鼠标状态是忙,哪位高手帮我看一眼是什么情况,谢谢了。

[解决办法]
Private Sub setclose(ByVal x As Form, ByVal y As Boolean)
If x.InvokeRequired Then
Dim d As New setcloses(AddressOf setclose)
Me.Invoke(d, New Object() {x, y})--->>>>x.Invoke(d, New Object() {x, y}
Else
If y Then
x.Show()
Else
x.Close()
End If
End If
End Sub

热点排行