development:csharp:threadpool

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,this);
 +}
  
 +private static void threadWorker(object obj)
 +{
 +    Form1 f = (Form1)obj;
 +    {
 +        if (f.comboFrom.InvokeRequired)
 +        {
 +            f.comboFrom.Invoke(new ComboAddThreadSafeDelegate(ComboAddThreadSafe), f, ComboItem);
 +        }
 +    }
 +}
 +
 +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<object> resultCallback = (theResults) =>
 +    {
 +        MessageBox.Show((string)theResults);
 +    };
 +    WaitCallback workItem = (dataOrSomeDetails) =>
 +    {
 +        string a = (string)dataOrSomeDetails;
 +        resultCallback(a + " someResults");
 +    };
 +    ThreadPool.QueueUserWorkItem(workItem, "text");
 +}
 +</code>
  • development/csharp/threadpool.txt
  • Last modified: 2021/06/02 11:32
  • by 127.0.0.1