473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to call BeginInvoke for a sub that has a parameter ?

How can I 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)


Jun 5 '06 #1
3 7527
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)

Jun 5 '06 #2
Thanks. It works.
I use asyncresult based on the example I got from the internet.
Is BeginInvoke faster than plain Invoke ?
"Charlie Brown" <cb****@duclaw.com> wrote in message
news:11*********************@f6g2000cwb.googlegrou ps.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)

Jun 5 '06 #3
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.

Jun 6 '06 #4

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

Similar topics

1
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my...
2
by: fred | last post by:
I'm writing an application invoking asynchon methods. I envision using the .NET thread pool since it matches well my needs. There is (at least) 2 methods to do that: using ThreadPool class...
1
by: Jeffrey Kingsley | last post by:
I would like to cancel a call to BeginInvoke of a delegate (i.e. kill the thread the call was made on). This would be done when a timeout occures for the waitone call to the WaitHandle object of...
2
by: rawCoder | last post by:
Hi I am having this InvalidOperationException with message Cannot call Invoke or InvokeAsync on a control until the window handle has been created This is raised when i try to invoke a method...
4
by: Tim Gallivan | last post by:
Hello group, I'm trying to develop a proof of concept webservice which asynchronously calls a function in a DLL. The function raises an event when it is finished, and works when used as part of...
2
by: Gerda | last post by:
Hi! I've implemented many times an asynchronous call of a method with a call backfunction successfully. But to implement this with VB.NET is not so successfully. I can implement all events...
5
by: Stephen Barrett | last post by:
I have read many threads related to async fire and forget type calls, but none have addressed my particular problem. I have a webpage that instantiates a BL object and makes a method call. The...
5
by: tcomer | last post by:
Hello, I'm working on an application that grabs some data from the web via HttpWebRequest. I'm using a local objects method to get the data, but the problem is that my form doesn't load until...
3
Frinavale
by: Frinavale | last post by:
Background An Event is a message sent out by an object to notify other objects that an action/trigger/state-change (ie. an event) has taken place. Therefore, you should use an event when an object's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.