Click here to Skip to main content
16,013,642 members
Home / Discussions / C#
   

C#

 
AnswerRe: BackgroundWorker Pin
Luc Pattyn12-Feb-10 3:57
sitebuilderLuc Pattyn12-Feb-10 3:57 
GeneralRe: BackgroundWorker Pin
RugbyLeague12-Feb-10 4:01
RugbyLeague12-Feb-10 4:01 
GeneralRe: BackgroundWorker Pin
RugbyLeague12-Feb-10 4:31
RugbyLeague12-Feb-10 4:31 
AnswerRe: BackgroundWorker Pin
Luc Pattyn12-Feb-10 8:50
sitebuilderLuc Pattyn12-Feb-10 8:50 
GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 11:58
professionalDaveyM6912-Feb-10 11:58 
AnswerRe: BackgroundWorker Pin
Luc Pattyn12-Feb-10 12:28
sitebuilderLuc Pattyn12-Feb-10 12:28 
GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 12:38
professionalDaveyM6912-Feb-10 12:38 
GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 9:45
professionalDaveyM6912-Feb-10 9:45 
You could rewrite the entire component and code it as you wish. There is publicly available source code available here[^] that can be easily adapted.

The easiest way however would be to subclass the existing component and add a readonly property as below:
C#
using System;
using System.ComponentModel;
using System.Windows.Forms;

public partial class FormMain : Form
{
    public FormMain()
    {
        InitializeComponent();
        Load += new EventHandler(Form1_Load);
    }

    void Form1_Load(object sender, EventArgs e)
    {
        CustomBackgroundWorker bgw = new CustomBackgroundWorker();
        bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
        bgw.RunWorkerAsync("Test");
    }

    private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        CustomBackgroundWorker bgw = sender as CustomBackgroundWorker;
        if (bgw != null && bgw.Argument != null)
        {
            MessageBox.Show((string)bgw.Argument);
        }
    }
}

public class CustomBackgroundWorker : BackgroundWorker
{
    private object argument;

    public new void RunWorkerAsync(object argument)
    {
        this.argument = argument;
        base.RunWorkerAsync(argument);
    }

    public object Argument
    {
        get { return argument; }
    }
}
Dave

Tip: Passing values between objects using events (C#)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 10:19
professionalDaveyM6912-Feb-10 10:19 
GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 11:56
professionalDaveyM6912-Feb-10 11:56 
AnswerRe: BackgroundWorker Pin
Luc Pattyn12-Feb-10 12:26
sitebuilderLuc Pattyn12-Feb-10 12:26 
GeneralRe: BackgroundWorker Pin
DaveyM6912-Feb-10 12:37
professionalDaveyM6912-Feb-10 12:37 
GeneralRe: BackgroundWorker Pin
Luc Pattyn12-Feb-10 12:47
sitebuilderLuc Pattyn12-Feb-10 12:47 
QuestionDocumentation description about the method and its parameters. Pin
Blubbo12-Feb-10 3:29
Blubbo12-Feb-10 3:29 
AnswerRe: Documentation description about the method and its parameters. Pin
R. Giskard Reventlov12-Feb-10 3:33
R. Giskard Reventlov12-Feb-10 3:33 
AnswerRe: Documentation description about the method and its parameters. Pin
dan!sh 12-Feb-10 3:36
professional dan!sh 12-Feb-10 3:36 
GeneralRe: Documentation description about the method and its parameters. Pin
Blubbo12-Feb-10 3:46
Blubbo12-Feb-10 3:46 
QuestionMultiPage-Application - Navigation Pin
PingOfDeath198312-Feb-10 3:09
PingOfDeath198312-Feb-10 3:09 
AnswerRe: MultiPage-Application - Navigation Pin
dan!sh 12-Feb-10 3:11
professional dan!sh 12-Feb-10 3:11 
QuestionAT command problem Pin
saeidfarahi12-Feb-10 2:44
saeidfarahi12-Feb-10 2:44 
AnswerRe: AT command problem Pin
Richard MacCutchan12-Feb-10 3:24
mveRichard MacCutchan12-Feb-10 3:24 
GeneralRe: AT command problem Pin
saeidfarahi12-Feb-10 3:28
saeidfarahi12-Feb-10 3:28 
GeneralRe: AT command problem Pin
Richard MacCutchan12-Feb-10 3:49
mveRichard MacCutchan12-Feb-10 3:49 
QuestionThread sychronization Pin
koleraba12-Feb-10 2:35
koleraba12-Feb-10 2:35 
AnswerRe: Hi Pin
Not Active12-Feb-10 4:07
mentorNot Active12-Feb-10 4:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.