HighTechTalks DotNet Forums  

VB .NET Form, Call Thread with Arguments and Invoke

Dotnet Distributed Applications microsoft.public.dotnet.distributed_apps


Discuss VB .NET Form, Call Thread with Arguments and Invoke in the Dotnet Distributed Applications forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
javiercaos@gmail.com
 
Posts: n/a

Default VB .NET Form, Call Thread with Arguments and Invoke - 08-16-2007 , 02:13 PM






Hi,

I'm developing a Windows form application, with multithreading and my
problem is this:

When i receive any data begining by "1", i need to create a thread
calling the sub "EscribirChat" with one argument.

This is the code that i have now:

Delegate Sub AñadirTextoChatCallBack(ByVal Texto As String)

Private ThreadChat As Thread = Nothing

Private Sub DatosRecibidosServer(ByVal Datos As String)
Select Case Datos.Chars(0)
Case "0" : OperacionInterna(Datos)
Case "1"
Me.ThreadChat = New Thread(AddressOf
Me.EscribirChat)
Me.ThreadChat.Start()
End Select
End Sub

Private Sub EscribirChat(ByVal Texto As String)
Me.AñadirTextoChat(Texto)
End Sub

Private Sub AñadirTextoChat(ByVal Texto As String)
If Me.TBSalidaChat.InvokeRequired Then
Dim d As New AñadirTextoChatCallBack(AddressOf
AñadirTextoChat)
Me.Invoke(d, New Object() {Texto})
Else
OperacionChat(Texto)
End If
End Sub

Private Sub OperacionChat(ByVal Datos As String)
Dim Tam As Integer = Convert.ToInt16(Datos.Substring(2,
3))
Dim Cadena As String

Cadena = Datos.Substring(6, Tam)
Me.TBSalidaChat.Text = Me.TBSalidaChat.Text & "<" &
Me.NombreOponente & "> : " & Cadena & vbCrLf
Me.TBSalidaChat.Select(Me.TBSalidaChat.Text.Length , 0)
Me.TBSalidaChat.ScrollToCaret()
End Sub


And Microsoft Visual Studio 2003 tell me:

"Method 'Private Sub EscribirChat(ByVal Texto As String)' does not
have the same signature as delegate 'Delegate Sub ThreadStart()'"

Can someone help me for solve this problem?.

Thank you very much.

Javi.


Reply With Quote
  #2  
Old   
AlexS
 
Posts: n/a

Default Re: VB .NET Form, Call Thread with Arguments and Invoke - 08-16-2007 , 05:58 PM






You created parameterized thread start when creating new Thread
(EscribirChat has parameter), but you call Thread.Start without parameters,
so compiler expects parameterless thread start object.

Try

Me.ThreadChat.Start(Datos)

Check ParameterizedThreadStart class and how to use it.


<javiercaos (AT) gmail (DOT) com> wrote

Hi,

I'm developing a Windows form application, with multithreading and my
problem is this:

When i receive any data begining by "1", i need to create a thread
calling the sub "EscribirChat" with one argument.

This is the code that i have now:

Delegate Sub AñadirTextoChatCallBack(ByVal Texto As String)

Private ThreadChat As Thread = Nothing

Private Sub DatosRecibidosServer(ByVal Datos As String)
Select Case Datos.Chars(0)
Case "0" : OperacionInterna(Datos)
Case "1"
Me.ThreadChat = New Thread(AddressOf
Me.EscribirChat)
Me.ThreadChat.Start()
End Select
End Sub

Private Sub EscribirChat(ByVal Texto As String)
Me.AñadirTextoChat(Texto)
End Sub

Private Sub AñadirTextoChat(ByVal Texto As String)
If Me.TBSalidaChat.InvokeRequired Then
Dim d As New AñadirTextoChatCallBack(AddressOf
AñadirTextoChat)
Me.Invoke(d, New Object() {Texto})
Else
OperacionChat(Texto)
End If
End Sub

Private Sub OperacionChat(ByVal Datos As String)
Dim Tam As Integer = Convert.ToInt16(Datos.Substring(2,
3))
Dim Cadena As String

Cadena = Datos.Substring(6, Tam)
Me.TBSalidaChat.Text = Me.TBSalidaChat.Text & "<" &
Me.NombreOponente & "> : " & Cadena & vbCrLf
Me.TBSalidaChat.Select(Me.TBSalidaChat.Text.Length , 0)
Me.TBSalidaChat.ScrollToCaret()
End Sub


And Microsoft Visual Studio 2003 tell me:

"Method 'Private Sub EscribirChat(ByVal Texto As String)' does not
have the same signature as delegate 'Delegate Sub ThreadStart()'"

Can someone help me for solve this problem?.

Thank you very much.

Javi.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.