Solved

Need help with ParameterizedThreadStart delegate

Posted on 2007-11-18
6
1,013 Views
Last Modified: 2012-08-14
I have defined two arrays that I need to pass to a thread:

            Service.isbnAndPrices[] initialISBNRetValue = new Service.isbnAndPrices[100];
            Service.isbnAndPrices[] isbnRetValue = new Service.isbnAndPrices[totalRecordCount];

I have defined the call to start the thread as:

                    ParameterizedThreadStart pts = new ParameterizedThreadStart(getISBNPricingData);
                    Thread t = new Thread(pts);
                    ArrayList al = new ArrayList();
                    al.Add(initialISBNRetValue);
                    al.Add(isbnRetValue);
                    t.Start(al);

and finally, the actual method that I want to run as a separate thread:

        private void getISBNPricingData(object data)
        {
            Cursor.Current = Cursors.AppStarting;
            Service.isbnAndPrices[] initialRetValue = (ArrayList)data[0];
            Service.isbnAndPrices[] retValue = (ArrayList)data[1];


The problem is the last two lines above; I am getting an error stating: Cannot apply indexing with [] to an expression of type object.

How do I fix this?

0
Comment
Question by:rmmarsh
  • 3
  • 3
6 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20308645
try with:

private void getISBNPricingData(object data)
        {
            Cursor.Current = Cursors.AppStarting;
            ArrayList array = (ArrayList)data;
            Service.isbnAndPrices[] initialRetValue = (Service.isbnAndPrices[])array[0];
            Service.isbnAndPrices[] retValue = (Service.isbnAndPrices[])array[1];

0
 

Author Comment

by:rmmarsh
ID: 20308678
Unbelievable!  Thank you soooo much!  Sometimes I just can't figure it out...

One more question:  what is the proper way to stop this thread so I don't have memory leaks?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20308699
Do you have any specific requirement with the thread stuff?
Usually you just have to return from your thread function.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:rmmarsh
ID: 20308712
Well, that would work also... but I have a "stop" button to stop the process... do I just use "suspend"?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20308739
use Abort().
Have a look for this simple tutorial about .net threads:
http://www.codeproject.com/cs/threads/csharp.asp
0
 

Author Closing Comment

by:rmmarsh
ID: 31409822
Thanks again...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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