How to use function in other class c# -
i put function checkproxy() in form1.cs works correctly , want move function checkproxy() other class if put checkproxy() in other class error invoke , richtextbox3
namespace test3 { public partial class form1 : form { public bool continuethreads = false; string[] proxylist = null; list<thread> threadlist = new list<thread>(); int proxynum = 0; public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { int n = (int)numericupdown1.value; thread[] tl = new thread[n + 1]; threadlist = tl.tolist(); (int = 0; <= n; i++) { threadlist[i] = new thread(new threadstart(checkproxy)); } (int = 0; <= n; i++) { threadlist[i].start(); } continuethreads = true; proxylist = richtextbox1.lines; } public void checkproxy() { while (continuethreads) { if (proxynum >= proxylist.length) { continuethreads = false; } if (proxynum < proxylist.length) { string proxy = proxylist[proxynum]; proxynum += 1; string info = ""; try { thread.sleep(1000); info += "live || " + proxy + environment.newline; this.invoke(new action(() => richtextbox3.text += info)); } catch { } } } } } }
your method checkproxy
uses form1
class members (continuethreads
, proxynum
, others) directly.
if want move outside of class (i'm not sure idea since method looks closely related class) - need refactor method , pass class members uses method input parameters
public void checkproxy(bool continuethreads.....)
Comments
Post a Comment