|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to call BeginInvoke for a sub that has a parameter ?I have a sub WriteInput that change the Text field txtInput with the value passed in its parameter. How can I call WriteInput using BeginInvoke ? The following codes gave me "parameter count mismatch" error. Public Delegate Sub WriteLineDelegate2(ByVal data() As Object) Public Sub WriteInputGL(ByVal data() As Object) Dim ar1 As IAsyncResult ar1 = BeginInvoke(New WriteLineDelegate2(AddressOf WriteInput), data) End Sub Private Sub WriteInput(ByVal data() As Object) Dim Line As String Line = CType(data(0), String) Me.txtInput.Text = Line End Sub Dim arrObject() As Object arrObject(0) = "this is a test" WriteInputGL(arrObject) Not sure why you are using the asyncresult but here is what can be done
Public Delegate Sub WriteLineDelegate2(ByVal data() As Object) Public Sub WriteInputGL(ByVal data() As Object) Dim worker As New WriteLineDelegate2(AddressOf WriteInput) worker.BeginInvoke(data, Nothing, Nothing) End Sub Private Sub WriteInput(ByVal data() As Object) Dim Line As String Line = CType(data(0), String) Me.txtInput.Text = Line End Sub Dim arrObject() As Object arrObject(0) = "this is a test" WriteInputGL(arrObject) Thanks. It works.
I use asyncresult based on the example I got from the internet. Is BeginInvoke faster than plain Invoke ? Show quoteHide quote "Charlie Brown" <cbr***@duclaw.com> wrote in message news:1149540550.054711.32060@f6g2000cwb.googlegroups.com... > Not sure why you are using the asyncresult but here is what can be done > > Public Delegate Sub WriteLineDelegate2(ByVal data() As Object) > > > Public Sub WriteInputGL(ByVal data() As Object) > Dim worker As New WriteLineDelegate2(AddressOf WriteInput) > worker.BeginInvoke(data, Nothing, Nothing) > End Sub > > > Private Sub WriteInput(ByVal data() As Object) > Dim Line As String > Line = CType(data(0), String) > Me.txtInput.Text = Line > End Sub > > > Dim arrObject() As Object > > > arrObject(0) = "this is a test" > WriteInputGL(arrObject) > Invoke will run synchronously meaning it will invoke a new thread, but
you will have to wait for that thread to finish before continuing, while BeginInvoke runs asynchronously and returns without waiting for the Invoked thread to finish.
Close form if no user action including mouse move over form.
Can't create AutoFiltered Excel worksheet using VB.NET Accessing inherited variables Textbox Lines Limit Define an object??? Use a System.Type in Generics? Newbie needs help with datagrid Read value of all columns from datatable together Generate Microsoft Office Document? CreateObject error |
|||||||||||||||||||||||