473,605 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

threads and delegates

newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.DynamicI nvoke(Nothing)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #1
8 2182
Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:
newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.DynamicI nvoke(Nothing)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #2
Patrik ,

How must i do it?

"Patrik Löwendahl [C# MVP]" wrote:
Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:
newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.DynamicI nvoke(Nothing)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #3
i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:
Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:
newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.DynamicI nvoke(Nothing)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #4
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
del1.BeginInvok e()
del2.BeginInvok e()
del3.BeginInvok e()
del4.BeginInvok e()
del5.BeginInvok e()
del6.BeginInvok e()
del7.BeginInvok e()
del8.BeginInvok e()
end sub
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:

Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:
newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.Dynam icInvoke(Nothin g)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #5
i have used this and error brings to me:

Argument not specified for parameter 'DelegateCallba ck' of 'Public
Overridable Function BeginInvoke(Del egateCallback As System.AsyncCal lback,
DelegateAsyncSt ate As Object) As System.IAsyncRe sult'. C:\Documents and
Settings\axe\Mi s documentos\Visu al
Studio\Projects \dominios_visua les\dominios_vi suales\Form1.vb 383 8
"Patrik Löwendahl [C# MVP]" wrote:
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
del1.BeginInvok e()
del2.BeginInvok e()
del3.BeginInvok e()
del4.BeginInvok e()
del5.BeginInvok e()
del6.BeginInvok e()
del7.BeginInvok e()
del8.BeginInvok e()
end sub
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:

Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:

newbie delegates question

i'm using this code:

sub empezar()
Dim del As MyDelSub
Dim del2 As MyDelSub
Dim delAll As [Delegate]
del = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
delAll = MulticastDelega te.Combine(del, del2)
delAll.Dynam icInvoke(Nothin g)
End Sub

and i'd like to launch 2 simultaneous delegates , How could i do it???

Jul 21 '05 #6
Sorry,

BeginInvoke need some extra arguments.

del1.BeginInvok e(null, null)
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i have used this and error brings to me:

Argument not specified for parameter 'DelegateCallba ck' of 'Public
Overridable Function BeginInvoke(Del egateCallback As System.AsyncCal lback,
DelegateAsyncSt ate As Object) As System.IAsyncRe sult'. C:\Documents and
Settings\axe\Mi s documentos\Visu al
Studio\Projects \dominios_visua les\dominios_vi suales\Form1.vb 383 8
"Patrik Löwendahl [C# MVP]" wrote:

Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
del1.BeginInvok e()
del2.BeginInvok e()
del3.BeginInvok e()
del4.BeginInvok e()
del5.BeginInvok e()
del6.BeginInvok e()
del7.BeginInvok e()
del8.BeginInvok e()
end sub
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:

Hi,

You will have to use BeginInvoke on del1 and del2. You will not need
delAll in that scenario.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net

axxegfx wrote:
>newbie delegates question
>
>i'm using this code:
>
>sub empezar()
>Dim del As MyDelSub
>Dim del2 As MyDelSub
>Dim delAll As [Delegate]
>del = New MyDelSub(Addres sOf hilo1)
>del2 = New MyDelSub(Addres sOf hilo2)
>delAll = MulticastDelega te.Combine(del, del2)
>delAll.Dyn amicInvoke(Noth ing)
>End Sub
>
>and i'd like to launch 2 simultaneous delegates , How could i do it???
>

Jul 21 '05 #7
OHHH my god, it's impossible

i use this:

Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub
Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)

'delAll = MulticastDelega te.Combine(del1 , del2, del3, del4, del5,
del6, del7, del8, del9, del10)
'delAll.Dynamic Invoke(Nothing)
del1.BeginInvok e(DBNull.Value, DBNull.Value)
del2.BeginInvok e(DBNull.Value, DBNull.Value)
a new error brings:

Error 1 Value of type 'System.DBNull' cannot be converted to
'System.AsyncCa llback'.C:\Docu ments and Settings\axe\Mi s documentos\Visu al
Studio\Projects \dominios_visua les\dominios_vi suales\Form1.vb 387 25

and it runs first delegate and then the other when firts has finished.

i'm trying to change de code to this:
function hilo(ByVal dominio As String, ByVal numero As String, ByRef
dirsAnalizados As Integer) As ArrayList
me.textbox1.tex t="HELLO"
end function
Delegate Function hiloDelegate(By Val dominio As String, ByVal numero As
String, ByRef dirsAnalizados As Integer) As ArrayList
Private Sub iniciar_hilos()
Dim ar(1) As IAsyncResult
Dim a As Integer = 0
Dim domino As String = ".com"
Dim hiloDelegate As New hiloDelegate(Ad dressOf hilo)
ar(0) = hiloDelegate.Be ginInvoke("", "", a, Nothing, Nothing)
'ar(1) = hiloDelegate.Be ginInvoke("", "", a, Nothing, Nothing)
Dim waitHandles() As WaitHandle = {ar(0).AsyncWai tHandle}
Do Until WaitHandle.Wait All(waitHandles , 500, False)
Loop
End Sub

but i get:

Illegal cross-thread operation: Control 'TextBox1' accessed from a thread
other than the thread it was created on.Stack trace where the illegal
operation occurred was:
at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.g et_WindowText()
at System.Windows. Forms.TextBoxBa se.get_WindowTe xt()
at System.Windows. Forms.Control.g et_Text()
at System.Windows. Forms.TextBoxBa se.set_Text(Str ing)
at System.Windows. Forms.TextBox.s et_Text(String)
at WindowsApplicat ion1.Form1.hilo (String, String, Int32&)
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink._PrivateP rocessMessage(I ntPtr, Object[], Object, Int32, Boolean, Object[]&)
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink.PrivatePr ocessMessage(Ru ntimeMethodHand le, Object[], Object, Int32, Boolean, Object[]&)
at
System.Runtime. Remoting.Messag ing.StackBuilde rSink.AsyncProc essMessage(IMes sage, IMessageSink)
at
System.Runtime. Remoting.Proxie s.AgileAsyncWor kerItem.ThreadP oolCallBack(Obj ect)
at System.Threadin g._ThreadPoolWa itCallback.Wait Callback_Contex t(Object)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext, ContextCallback ,
Object, StackCrawlMark& )
at System.Threa... "

"Patrik Löwendahl [C# MVP]" wrote:
Sorry,

BeginInvoke need some extra arguments.

del1.BeginInvok e(null, null)
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i have used this and error brings to me:

Argument not specified for parameter 'DelegateCallba ck' of 'Public
Overridable Function BeginInvoke(Del egateCallback As System.AsyncCal lback,
DelegateAsyncSt ate As Object) As System.IAsyncRe sult'. C:\Documents and
Settings\axe\Mi s documentos\Visu al
Studio\Projects \dominios_visua les\dominios_vi suales\Form1.vb 383 8
"Patrik Löwendahl [C# MVP]" wrote:

Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
del1.BeginInvok e()
del2.BeginInvok e()
del3.BeginInvok e()
del4.BeginInvok e()
del5.BeginInvok e()
del6.BeginInvok e()
del7.BeginInvok e()
del8.BeginInvok e()
end sub
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:

i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:

>Hi,
>
>You will have to use BeginInvoke on del1 and del2. You will not need
>delAll in that scenario.
>
>--
>Patrik Löwendahl [C# MVP]
>http://www.lowendahl.net/ || http://www.cshrp.net
>
>axxegfx wrote:
>
>
>>newbie delegates question
>>
>>i'm using this code:
>>
>>sub empezar()
>>Dim del As MyDelSub
>>Dim del2 As MyDelSub
>>Dim delAll As [Delegate]
>>del = New MyDelSub(Addres sOf hilo1)
>>del2 = New MyDelSub(Addres sOf hilo2)
>>delAll = MulticastDelega te.Combine(del, del2)
>>delAll.Dyn amicInvoke(Noth ing)
>>End Sub
>>
>>and i'd like to launch 2 simultaneous delegates , How could i do it???
>>
>

Jul 21 '05 #8
Patrik i see the big light
could you help me with this code??

Imports System.Threadin g
Public Class Form1

Function hilo(ByVal dominio As String, ByVal numero As Integer, ByRef
resultado As String) As String

End Function
Delegate Function hiloDelegate(By Val dominio As String, ByVal numero As
Integer, ByRef resultado As String) As String

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim ar(1) As IAsyncResult
Dim a As Integer = 0
Dim dominio(1), resultado As String
dominio(1) = "terra.com"
Dim hiloDelegate As New hiloDelegate(Ad dressOf hilo)
ar(0) = hiloDelegate.Be ginInvoke(domin io(1), "", resultado)
Me.TextBox1.Tex t = "HOLA"
Dim waitHandles() As WaitHandle = {ar(0).AsyncWai tHandle}
Do Until WaitHandle.Wait All(waitHandles , 500, False)
Loop
End Sub

End Class

sure it's so easy but i'm a newbie and young programmer

it brings to me:
Error 1 Argument not specified for parameter 'DelegateCallba ck' of 'Public
Overridable Function BeginInvoke(dom inio As String, numero As Integer, ByRef
resultado As String, DelegateCallbac k As System.AsyncCal lback,
DelegateAsyncSt ate As Object) As System.IAsyncRe sult'. C:\Documents and
Settings\axe\Co nfiguración local\Datos de programa\Tempor ary
Projects\Window sApplication1\F orm1.vb 15 16
"Patrik Löwendahl [C# MVP]" wrote:
Sorry,

BeginInvoke need some extra arguments.

del1.BeginInvok e(null, null)
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:
i have used this and error brings to me:

Argument not specified for parameter 'DelegateCallba ck' of 'Public
Overridable Function BeginInvoke(Del egateCallback As System.AsyncCal lback,
DelegateAsyncSt ate As Object) As System.IAsyncRe sult'. C:\Documents and
Settings\axe\Mi s documentos\Visu al
Studio\Projects \dominios_visua les\dominios_vi suales\Form1.vb 383 8
"Patrik Löwendahl [C# MVP]" wrote:

Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
del1.BeginInvok e()
del2.BeginInvok e()
del3.BeginInvok e()
del4.BeginInvok e()
del5.BeginInvok e()
del6.BeginInvok e()
del7.BeginInvok e()
del8.BeginInvok e()
end sub
--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

axxegfx wrote:

i've proved this
Sub empezar()
Dim del1 As MyDelSub
Dim del2 As MyDelSub
Dim del3 As MyDelSub
Dim del4 As MyDelSub
Dim del5 As MyDelSub
Dim del6 As MyDelSub
Dim del7 As MyDelSub
Dim del8 As MyDelSub
Dim del9 As MyDelSub
Dim del10 As MyDelSub

Dim delAll As [Delegate]
del1 = New MyDelSub(Addres sOf hilo1)
del2 = New MyDelSub(Addres sOf hilo2)
del3 = New MyDelSub(Addres sOf hilo3)
del4 = New MyDelSub(Addres sOf hilo4)
del5 = New MyDelSub(Addres sOf hilo5)
del6 = New MyDelSub(Addres sOf hilo6)
del7 = New MyDelSub(Addres sOf hilo7)
del8 = New MyDelSub(Addres sOf hilo8)
del9 = New MyDelSub(Addres sOf hilo9)
del10 = New MyDelSub(Addres sOf hilo10)
BeginInvoke(del 1)
BeginInvoke(del 2)
BeginInvoke(del 3)
BeginInvoke(del 4)
BeginInvoke(del 5)
BeginInvoke(del 6)
BeginInvoke(del 7)
BeginInvoke(del 8)
BeginInvoke(del 9)
BeginInvoke(del 10)
end sub

but it seems only las thread del10 runs, but de textbox that shows results
only it runs with del10 first

"Patrik Löwendahl [C# MVP]" wrote:

>Hi,
>
>You will have to use BeginInvoke on del1 and del2. You will not need
>delAll in that scenario.
>
>--
>Patrik Löwendahl [C# MVP]
>http://www.lowendahl.net/ || http://www.cshrp.net
>
>axxegfx wrote:
>
>
>>newbie delegates question
>>
>>i'm using this code:
>>
>>sub empezar()
>>Dim del As MyDelSub
>>Dim del2 As MyDelSub
>>Dim delAll As [Delegate]
>>del = New MyDelSub(Addres sOf hilo1)
>>del2 = New MyDelSub(Addres sOf hilo2)
>>delAll = MulticastDelega te.Combine(del, del2)
>>delAll.Dyn amicInvoke(Noth ing)
>>End Sub
>>
>>and i'd like to launch 2 simultaneous delegates , How could i do it???
>>
>

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2149
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on worker threads. Yes I have gotten it to work, kind-of - that is I have gotten the shelled processes off of the UI thread (I think?). But the UI still is not updating properly! Still I have white boxes for forms, label text that does not update, and...
22
4047
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
12
3156
by: Grant | last post by:
I am having great difficulty understanding this and any code samples I find online are kilometres long and complicated to understand...Please could someone give me a simple exampe of how to get a delegate passed to my worked class so that my main form can update its progress bar? I know it has something to do with begininvoke and endinvoke etc, but I just need a simple sample to understand the convention. Code from my main form:...
13
2508
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled 'ThreadPool Class ') .... however I would like to ensure that all my ThreadPool threads have completed before I exit my Main function.
11
20337
by: Peter Kirk | last post by:
Hi there I am looking at using a thread-pool, for example one written by Jon Skeet (http://www.yoda.arachsys.com/csharp/miscutil/). Can anyone tell me if this pool provides the possibility to wait for all its threads to finish? For example, if I start 20 threads: CustomThreadPool pool = new CustomThreadPool("PetersThreadPool"); ThreadMethod m = new ThreadMethod(InsertThread);
7
1886
by: Waleed AlRashoud | last post by:
Hi All, I hvae worker class to manage the application inside worker : worker creates (n) number of threads to do IO operations. The Problem Is: to handle all threads : , , I have to keep worker process inside while statement: while (true)
14
3245
by: Lior Amar | last post by:
Quick question about threads and delegates. I have the following scenario Thread A (CLASSA) spawns Thread B (CLASSB) and passes it a DelegateA to a callback Thread B Invokes a DelegateB asynchronously (could be a timer but then we get Thread C) Upon completion of DelegateB, Thread B would like to callback ThreadA using DelegateA but as we all know the call to DelegateA is running in ThreadB. Is
15
2604
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched, the main thread waits. At the completion of each subthread, the mainthread checks all 12 thread objects to see if they are done. If they are, raise an event that says we're done. So, it's kinda like this: ProcessThread - Creates a ProcessObject
6
2489
by: Jon Davis | last post by:
I've used delegates fairly heavily for several years in C# for event handling and for starting threads. Does anyone have any real-world scenarios where delegates were both extremely useful and extremely appropriate (as opposed to other programmatic means or mechanisms) that were NOT related to events and ThreadStarts? Thanks, Jon
14
2818
by: Gotch | last post by:
Hi all, I've recently digged into C# and the whole .Net stuff. Particularly I found the idea of adding Events and Delegates to the C# language very interesting and I'm trying to use them in every weird way that comes to my mind. Particularly I'm struggling to find a way to use events between threads. In particular I'd like to know how to rise and event from a thread and have it received from the delegate in another thread (I mean the...
0
8009
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
7938
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8298
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5892
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1279
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.