[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Background Worker and returning values

Posted on 2006-11-09
5
Medium Priority
?
479 Views
Last Modified: 2012-05-05
Hello all. Morning question...
I have the main thread running my main form. I use a backgroundworker when user click button to use a webservice that controls european VAT. my code is:

//...
MBForm.Showdialog() // form whre is shown the progress of the webservice running on the Background Thread
Backgroundworker.RunWorkerASynch();

//... BackGroundWorker_Dowork()
Webservice.run()

All that I need is: How can I have retuning values when the background worker has finished the work? I mean the Webservice is controlling the european VAT returning bool valid and string name and string address. How can I have this three returning values for using it on the main Thread? Do I have to assingn these values on a global variable of is there a better way? Thx in advance
0
Comment
Question by:puckkk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1196 total points
ID: 17905249
You can pass result of background operation using DoWorkEventArgs.Result property.

Backgroundworker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Backgroundworker_RunWorkerCompleted);

void BackGroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
    // your existing code

    // Make result
    OperationResult r = new Result();   // OperationResult  is your class which contains results of background operation
    r.Name = ...;
    r.Address = ...;     // fill result properties
    e.Result = r;
}

void Backgroundworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
     if ( e.Error != null )
     {
         // report error
     }
     else if ( e.Cancelled )
     {
          // report cancellation
     }
     else
     {
         OperationResult r = (OperationResult)e.Result;
         // get result here
     }
}
 
0
 

Author Comment

by:puckkk
ID: 17905283
Nice. Thx a lot agian man.
0
 

Author Comment

by:puckkk
ID: 17912268
Sorry Alex, just one more thing...
   OperationResult r = new Result();   // OperationResult  is your class which contains results of background operation
 r.Name = ...;
    r.Address = ...;     // fill result properties

What is the best way to create OperationResult class?

public class Operation Result
{
        string name;
        string address
        OperationResult(string _name, string address)
        {
             name=_name;
             address = _address;

        }
}

Or is there a better way to create an object assigning to properties to it? Thx again
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17912525
Any way that is convenient for you: class with constructor and read-only properties, class with read/write properties. Anything that allows to keep information and read it. As example of such clas, which is designed only for keeping parameters, see ProcessStartInfo class.
0
 

Author Comment

by:puckkk
ID: 17912532
Thx a lot.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question