Create multiple instances of an object c# -
i'm trying implement instantiate object multiple times. following code create html listener , want them alive till end of process. don't want write down 10 times rather find way automatically create 10 times.
i tried listeners don't seem running.
public static void multipleproxy() { var proxies = new list<sockswebproxy>(); (int = 1; <= 10; i++) { proxies.add(proxy(i)); } } public static sockswebproxy proxy(int i) { var proxy = new sockswebproxy(new proxyconfig(ipaddress.parse("127.0.0.1"), 7000 + i, ipaddress.parse("127.0.0.1"), 9000 + i, proxyconfig.socksversion.five)); return proxy; }
you creating 10 instances of sockswebproxy. problem code objects go out of scope method create them exits, leaving them eligible garbage collection. solve problem, can move list e.g. class scope.
private static list<sockswebproxy> proxies = new list<sockswebproxy>(); public static void multipleproxy() { (int = 1; <= 10; i++) { proxies.add(proxy(i)); } }
multiple calls multipleproxy() keep adding list design.
Comments
Post a Comment