Click here to Skip to main content
15,890,946 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create an instance whose name is given as a string. the name of identifier should b the string that is given

means SomeClass <string provided=""> = new SomeClass();

i need to Abort some threads whose names are defined by some regular expression

lets say

t is 1st thread
ta is secound
taa is third
tba is forth
c is fifth
and so on...

so Abort all thread whose identifier starts from ta.
Posted

Reflection can be used to do that. I suspect there's a much better way, though, like creating a dictionary to map threads to names.
 
Share this answer
 
yp Dictionary has donw the work
thanks bro

XML
Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add( "t","thread1");
            dic.Add( "ta","thread2");
            dic.Add( "taa","thread3");
            dic.Add( "tba","thread4");
            dic.Add( "tbb","thread5");
            dic.Add( "c","thread6");
            List<string> k = dic.Keys.ToList<string>();
            for(int i=0 ;i<k.Count;i++)
                if (Regex.IsMatch(k[i], "ta"))
                {
                    dic.Remove(k[i]);
                    Console.WriteLine(k[i]);
                }


this is what i did
 
Share this answer
 

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