473,407 Members | 2,314 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,407 software developers and data experts.

Multiple Args to Background worker

I have set up a background worker and now find I need to give it multiple arguments.
What is the best way of doing this? An example would be nice.
Dec 26 '05 #1
4 22567
Hi,

"John Veldthuis" <wh******@you.spam.me.com> wrote in message
news:g8********************************@4ax.com...
I have set up a background worker and now find I need to give it multiple
arguments.
What is the best way of doing this? An example would be nice.


I assume your talking about BackgroundWorker (NET2.0 component). Well you
can pass one argument, if you need to pass multiple then you could use a
class, a Hashtable or an array to group them and then pass that.

* Example using an array:

' start BackgroundWorker
BackgroundWorker1.RunWorkerAsync( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e
As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Dim args As Object() = DirectCast( e.Argument, Object() )

Dim arg1 As Integer = CInt(args(0))
Dim arg2 As String = CStr(args(1))

End Sub
HTH,
Greetings

Dec 26 '05 #2
On Tue, 27 Dec 2005 11:41:18 +1300, John Veldthuis <wh******@you.spam.me.com> wrote:
I have set up a background worker and now find I need to give it multiple arguments.
What is the best way of doing this? An example would be nice.


Also forgot I need to return multiple results as well.

Dec 26 '05 #3
Hi,

"John Veldthuis" <wh******@you.spam.me.com> wrote in message
news:gt********************************@4ax.com...
On Tue, 27 Dec 2005 11:41:18 +1300, John Veldthuis
<wh******@you.spam.me.com> wrote:
I have set up a background worker and now find I need to give it multiple
arguments.
What is the best way of doing this? An example would be nice.


Also forgot I need to return multiple results as well.


That doesn't change much, as per my previous reply you could use an array,
Hashtable or class to group parameters and pass them as an object (for
e.Argument and e.Result ):

* Example using an array (multiple args & results):

' start BackgroundWorker
BackgroundWorker1.RunWorkerAsync( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e
As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Dim args As Object() = DirectCast( e.Argument, Object() )

Dim arg1 As Integer = CInt(args(0))
Dim arg2 As String = CStr(args(1))

' do something

e.Result = New Object() { -1, "test" }

End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object,
ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles
BackgroundWorker1.RunWorkerCompleted
Dim ret As Object() = DirectCast( e.Result, Object() )

Dim ret1 As Integer = CInt(ret(0))
Dim ret2 As String = CStr(ret(1))
End Sub

HTH,
Greetings
Dec 27 '05 #4
On Tue, 27 Dec 2005 00:38:29 +0100, "Bart Mermuys" <bm*************@hotmail.com> wrote:
Hi,

"John Veldthuis" <wh******@you.spam.me.com> wrote in message
news:g8********************************@4ax.com.. .
I have set up a background worker and now find I need to give it multiple
arguments.
What is the best way of doing this? An example would be nice.


I assume your talking about BackgroundWorker (NET2.0 component). Well you
can pass one argument, if you need to pass multiple then you could use a
class, a Hashtable or an array to group them and then pass that.

* Example using an array:

' start BackgroundWorker
BackgroundWorker1.RunWorkerAsync( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e
As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Dim args As Object() = DirectCast( e.Argument, Object() )

Dim arg1 As Integer = CInt(args(0))
Dim arg2 As String = CStr(args(1))

End Sub


Thanks, Just what the doctor ordered for part one.
Dec 27 '05 #5

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

Similar topics

5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
21
by: Doug Thews | last post by:
I was noticing that when I run a multi-threaded app from within the IDE and then I close the main form (which spun off all of the threads), that the Stop/Pause VCR buttons in the debugger are still...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
5
by: Michael M. | last post by:
I have the following code (listed at bottom of post) that pings a small range of IP address to see which ones are alive. To speed things up a little I am trying to use more than one thread,...
27
by: cmdolcet69 | last post by:
Can anyone tell me if its possible to do multiple event args in vb.net?
2
by: scriptlearner | last post by:
OS: Solaris 9 Python Version: 2.4.4 I need to log certain data in a worker thread; however, I am getting an error now when I use two worker threads. I think the problem comes from the line...
3
by: scriptlearner | last post by:
I am trying to put up a queue (through a logging thread) so that all worker threads can ask it to log messages. However, the problem I am facing is that, well, the logging thread itself is running...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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 project—planning, coding, testing,...

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.