We help IT Professionals succeed at work.

Passing a string through a BackgroundWorker's RunWorkerAsync

gilllyo
gilllyo asked
on
Medium Priority
696 Views
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();
MessageBox::Show(arg);
this->threadPleaseWait->RunWorkerAsync(arg);

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
Comment
Watch Question

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

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

See: DoWorkEventArgs.Argument Property

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
HAve you tried to use safe_cast instead ?

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

Author

Commented:
Thanks

I have fixed that up...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.