473,813 Members | 4,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22631
Hi,

"John Veldthuis" <wh******@you.s pam.me.com> wrote in message
news:g8******** *************** *********@4ax.c om...
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 BackgroundWorke r (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 BackgroundWorke r
BackgroundWorke r1.RunWorkerAsy nc( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorke r1_DoWork(ByVal sender As System.Object, ByVal e
As System.Componen tModel.DoWorkEv entArgs) Handles BackgroundWorke r1.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.s pam.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.s pam.me.com> wrote in message
news:gt******** *************** *********@4ax.c om...
On Tue, 27 Dec 2005 11:41:18 +1300, John Veldthuis
<wh******@you.s pam.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 BackgroundWorke r
BackgroundWorke r1.RunWorkerAsy nc( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorke r1_DoWork(ByVal sender As System.Object, ByVal e
As System.Componen tModel.DoWorkEv entArgs) Handles BackgroundWorke r1.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 BackgroundWorke r1_RunWorkerCom pleted(ByVal sender As Object,
ByVal e As System.Componen tModel.RunWorke rCompletedEvent Args) Handles
BackgroundWorke r1.RunWorkerCom pleted
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.s pam.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 BackgroundWorke r (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 BackgroundWorke r
BackgroundWork er1.RunWorkerAs ync( New Object() { 10, "test" } )

' DoWork event
Private Sub BackgroundWorke r1_DoWork(ByVal sender As System.Object, ByVal e
As System.Componen tModel.DoWorkEv entArgs) Handles BackgroundWorke r1.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
10680
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 thread is spawned (threading module) and this thread starts listening for data on a socket. When someone connects, a new thread is spawned, It needs to do I/O on that socket and open a GUI window so the user can communicate with the client...
21
1639
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 available & working. It's like closing the form did not actually cancel the threads. From my earlier discussions on the newsgroup, I know how people already feel about Thread.Abort(), so I was wondering what I need to do to "clean up" when...
9
23089
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 to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
6
5002
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
8
5376
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 this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
5
5562
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, problem is instead of returning: 192.168.0.1 online
27
2135
by: cmdolcet69 | last post by:
Can anyone tell me if its possible to do multiple event args in vb.net?
2
4091
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 logging.info('Thread Object (%d):(%d), Time:%s in seconds %d'% (self.no,self.duration,time.ctime(),time.time())) when multiple worker thread is trying to update the log files. What did I do wrong? Should I lock the log file before writing to
3
5744
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 forever. It does not know when it should exit. Any suggestion? None of the worker threads knows for sure when the logging thread should exit since they don't know what other worker threads are doing. I also try to set a time limit for the...
0
10665
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10406
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
10139
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
9221
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, and deployment—without 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
7681
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
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.