Link to home
Start Free TrialLog in
Avatar of gilllyo
gilllyo

asked on

Passing a string through a BackgroundWorker's RunWorkerAsync

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
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chokehold
Chokehold

HAve you tried to use safe_cast instead ?
BTW, sender is BackgroundWorker itself. You need to cast it to BackgroundWorker and use inside of DoWork function.
Avatar of gilllyo

ASKER

Thanks

I have fixed that up...