473,387 Members | 1,486 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,387 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 22564
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
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.