no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | development:csharp:threadpool [2021/06/02 11:32] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Threadpool ====== | ||
+ | <code c#> | ||
+ | private static aaa() | ||
+ | { | ||
+ | ThreadPool.QueueUserWorkItem(threadWorker, | ||
+ | } | ||
+ | private static void threadWorker(object obj) | ||
+ | { | ||
+ | Form1 f = (Form1)obj; | ||
+ | { | ||
+ | if (f.comboFrom.InvokeRequired) | ||
+ | { | ||
+ | f.comboFrom.Invoke(new ComboAddThreadSafeDelegate(ComboAddThreadSafe), | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | private delegate void ComboAddThreadSafeDelegate(Form1 f, String val); | ||
+ | private static void ComboAddThreadSafe(Form1 f, String val) | ||
+ | { | ||
+ | f.comboFrom.Items.Add(val); | ||
+ | } | ||
+ | |||
+ | |||
+ | //or | ||
+ | |||
+ | private static aaa() | ||
+ | { | ||
+ | Action< | ||
+ | { | ||
+ | MessageBox.Show((string)theResults); | ||
+ | }; | ||
+ | WaitCallback workItem = (dataOrSomeDetails) => | ||
+ | { | ||
+ | string a = (string)dataOrSomeDetails; | ||
+ | resultCallback(a + " someResults" | ||
+ | }; | ||
+ | ThreadPool.QueueUserWorkItem(workItem, | ||
+ | } | ||
+ | </ |