Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using the following code:

private sealed class BackgroundWorkState
        {
            public ArrayList[] str { get; set; }
            public ArrayList searchtext_pass { get; set; }
            //public string SomethingElse { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BackgroundWorkState workerState = new BackgroundWorkState
                 {
                     searchtext_pass = ReadMSXls(),
                     str = ReadMsWord(),
                 };
    
    backgroundWorker.RunWorkerAsync(workerState);
        }


I need to pass the searchtext_pass to the function ReadMsWord(), but when I try
str=ReadMsWord(searchtext_pass)

it says searchtext_pass is not available in this context. Please advice.
Posted

Create BackgroundWorkState constructor which takes the parameter. Then in calling
BackgroundWorkState workerState = new BackgroundWorkState set the parameter...

Not clear if ReadMSXLs() and ReadMSWord are class methods or outside sources...but anyhow you set search text in constructor of the background work state (that is you call ReadMSXls before instantiating BackgroundWorkState.

I hope that helps :)
 
Share this answer
 
searchtext_pass is a property of the BackgroundWorkState class - so you need an instance of the class in order to access it - just as you need an instance of a car in order to look in the glove box!

So you need something like:
C#
str=ReadMsWord(myInstanceOfABackgroundWorkState.searchtext_pass);

But you can't easily access it because it's a property of the class instance you are trying to construct so it doesn't really exist yet!
Try this:
C#
BackgroundWorkState workerState = new BackgroundWorkState();
workerState.searchtext_pass = ReadMSXls();
workerState.str = ReadMsWord(workerState.searchtext_pass);
 
Share this answer
 
Comments
Tejas Shastri 17-Oct-14 2:32am    
tried it .. but now when I do this:
<pre>public ArrayList[] ReadMsWord(ArrayList searchtext_pass)
{....
return str;
}</pre>

it underlines ReadMsWord and says : not all code paths return a value..
Tejas Shastri 17-Oct-14 2:35am    
Ifixed it.. Thanks :)
OriginalGriff 17-Oct-14 3:25am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900