开发者

Threading with parameters of type string

Using ParameterizedThreadStart wou开发者_如何学Gold almost work but it requires object as parameter, which feels very wrong. Is it possible to pass a String through ParameterizedThreadStart?

        public void OpenUDirectory(String Directory)
        {
              Items.Clear();
              foreach (FileInfo FI in new DirectoryInfo(Directory).GetFiles())
              {
                    Items.Add(FI.Name);
              }
        }

I came up with the idea of adding an extension constructor to ParameterizedThreadStart so that I could cast String to Object and call the base method, but is there a cleaner way?

I'm sure I need to call the Invoke method so I have a delegate:

    public delegate void OpenDD(String Directory);


You have to box is as an object when you start the thread. Then cast it back to a string and call your method.

That is the way it works since it gives the greatest range of flexibility.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜