Passing a string through a BackgroundWorker's RunWorkerAsync

Posted on 2006-03-29
Last Modified: 2008-02-01
I have a Bacground Worker where it needs a string. I have put the string in the RunWorkerAsync function but when I try to cast the sender variable back to a string with the following line..

Calling method:

String^ arg=this->GenerateArg();

casting Method

String args = dynamic_cast<String^>(sender);

arg is a String^, I get what I expect in the message box but when casting the 'args' value is null
Question by:gilllyo
    LVL 48

    Accepted Solution

    You must extract argument from DoWorkEventArgs^ e parameter, I guess it should be:

    String^ args = dynamic_cast<String^>(e->Argument);

    See: DoWorkEventArgs.Argument Property
    LVL 2

    Expert Comment

    HAve you tried to use safe_cast instead ?
    LVL 48

    Expert Comment

    BTW, sender is BackgroundWorker itself. You need to cast it to BackgroundWorker and use inside of DoWork function.

    Author Comment


    I have fixed that up...

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Microsoft vcsetup.exe and vcssetup.exe 8 380
    Setting font in GroupBox 10 122
    Need some help with delete a recordset 7 116
    template declaration 35 132
    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now