开发者

Passing delegate with return type other than void in thread

开发者 https://www.devze.com 2022-12-22 08:52 出处:网络
I want to pass a delegate with the return 开发者_JAVA技巧type as ArrayList as parameter of thread and want to store the values in an ArrayList as well. Any help in this regard will be appreciated.Inst

I want to pass a delegate with the return 开发者_JAVA技巧type as ArrayList as parameter of thread and want to store the values in an ArrayList as well. Any help in this regard will be appreciated.


Instead of having a return value you could try passing in another parameter by reference:

private class ThreadArguments
{    
    public ArrayList List1 { get; set; }
    public ArrayList List2 { get; set; }

    public ThreadArguments(ArrayList list1, ref ArrayList list2)
    {
        this.List1 = list1;
        this.List2 = list2;
    }
}

Thread myThread = new Thread(new ParameterizedThreadStart(...));
myThread.Start(args);

So the return value is effectively replaced by list2.

0

精彩评论

暂无评论...
验证码 换一张
取 消