Solved

Need help with ParameterizedThreadStart delegate

Posted on 2007-11-18
6
1,032 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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