Updating Form UI controls from any thread.

Here is a general pattern you can use to update a Form from any thread.  Surface your method as a public method.  Now any thread can call this method that has a reference to the form object.  Inside that public method, just check the "InvokeRequired" value and call BeginInvoke on a delegate for a worker method or call the method directly if invoke is not required (i.e. called via another method in the same thread).  The delegate is required so we can call the method async using the BeginInvoke method.  Such as:
  
private delegate void AppendDelegate(string message);
 
  public void AppendString(string msg)
  {
   if ( InvokeRequired )
    BeginInvoke(new AppendDelegate(AppendStringToRTB), new object[]{msg});
   else
    AppendStringToRTB(msg);
  }
 
  private void AppendStringToRTB(string msg)
  {
   if ( msg == null )
    return;
   this.rtbOutput.AppendText(msg);
  }
 
Now you can call AppendString() either from inside the form or from another thread.  This is thread safe as the request is queued into the form’s event queue and handled by the form’s UI thread.  Also note that because we call BeginInvoke on a UI method, EndInvoke is not required.  This a special exception made for calling delegates on UI controls.
 
–William
Advertisements
This entry was posted in C#. Bookmark the permalink.

5 Responses to Updating Form UI controls from any thread.

  1. Unknown says:

    http://www.batteryfast.com/asus/f3.htm Asus f3 Battery http://www.batteryfast.com/toshiba/pa3594u-1brs.htm Toshiba pa3594u-1brs Battery http://www.batteryfast.com/toshiba/pa3593u-1bas.htm Toshiba pa3593u-1bas Battery http://www.batteryfast.com/toshiba/pabas111.htm Toshiba pabas111 Battery http://www.batteryfast.com/dell/xps-m1530.htm Dell xps m1530 Battery http://www.batteryfast.com/hp/tx2000.htm Hp tx2000 Battery http://www.batteryfast.com/hp/pavilion-tx1000.htm Hp pavilion tx1000 Battery http://www.batteryfast.com/dell/xps-m1730.htm Dell xps m1730 Battery http://www.batteryfast.com/hp/pavilion-dv6.htm Hp pavilion dv6 Battery http://www.batteryfast.com/toshiba/pa3395u-1brs.htm Toshiba pa3395u-1brs Battery http://www.batteryfast.com/toshiba/pa3421u-1brs.htm Toshiba pa3421u-1brs Battery http://www.batteryfast.com/toshiba/pa3451u-1brs.htm Toshiba pa3451u-1brs Battery http://www.batteryfast.com/toshiba/pa3399u-1brs.htm Toshiba pa3399u-1brs Battery http://www.batteryfast.com/toshiba/pa3399u-2bas.htm Toshiba pa3399u-2bas Battery http://www.batteryfast.com/toshiba/satellite-a100.htm Toshiba satellite a100 Battery http://www.batteryfast.com/toshiba/satellite-m40.htm Toshiba satellite m40 Battery http://www.batteryfast.com/toshiba/satellite-m45.htm Toshiba satellite m45 Battery http://www.batteryfast.com/toshiba/satellite-m55.htm Toshiba satellite m55 Battery http://www.batteryfast.com/toshiba/pa3356u.htm Toshiba pa3356u Battery http://www.batteryfast.com/toshiba/pa3356u-1bas.htm Toshiba pa3356u-1bas Battery http://www.batteryfast.com/toshiba/pa3356u-1brs.htm Toshiba pa3356u-1brs Battery http://www.batteryfast.com/toshiba/pa3356u-2brs.htm Toshiba pa3356u-2brs Battery http://www.batteryfast.com/toshiba/pa3456u-1brs.htm Toshiba pa3456u-1brs Battery http://www.batteryfast.com/toshiba/portege-m500.htm Toshiba portege m500 Battery http://www.batteryfast.com/toshiba/pa3451u.htm Toshiba pa3451u Battery http://www.batteryfast.com/toshiba/pabas067.htm Toshiba pabas067 Battery http://www.batteryfast.com/toshiba/pa3465u-1brs.htm Toshiba pa3465u-1brs Battery http://www.batteryfast.com/toshiba/pa3534u-1brs.htm Toshiba pa3534u-1brs Battery http://www.batteryfast.com/toshiba/pa3533u-1bas.htm Toshiba pa3533u-1bas Battery http://www.batteryfast.com/toshiba/satellite-a205.htm Toshiba satellite a205 Battery http://www.batteryfast.com/toshiba/pa3534u-1bas.htm Toshiba pa3534u-1bas Battery http://www.batteryfast.com/uniwill/255-3s4400-g1l1.htm Uniwill 255-3s4400-g1l1 Battery http://www.batteryfast.com/uniwill/un255.htm Uniwill un255 Battery

  2. Unknown says:

    http://www.globallaptopbatteries.co.uk/hp/mini-1001.htm Hp mini 1001 Battery http://www.globallaptopbatteries.co.uk/hp/mini-1050.htm Hp mini 1050 Battery http://www.globallaptopbatteries.co.uk/hp/nc2400.htm Hp nc2400 Battery http://www.globallaptopbatteries.co.uk/hp/nc4000.htm Hp nc4000 Battery http://www.globallaptopbatteries.co.uk/hp/nc6000.htm Hp nc6000 Battery http://www.globallaptopbatteries.co.uk/hp/nc6100.htm Hp nc6100 Battery http://www.globallaptopbatteries.co.uk/hp/nc6120.htm Hp nc6120 Battery http://www.globallaptopbatteries.co.uk/hp/nc6400.htm Hp nc6400 Battery http://www.globallaptopbatteries.co.uk/hp/nc8000.htm Hp nc8000 Battery http://www.globallaptopbatteries.co.uk/hp/nc8230.htm Hp nc8230 Battery http://www.globallaptopbatteries.co.uk/hp/nc8430.htm Hp nc8430 Battery http://www.globallaptopbatteries.co.uk/hp/nx7000.htm Hp nx7000 Battery http://www.globallaptopbatteries.co.uk/hp/nx8200.htm Hp nx8200 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv2000.htm Hp pavilion dv2000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv6000.htm Hp pavilion dv6000 Battery http://www.globallaptopbatteries.co.uk/dell/inspiron-5100.htm Dell inspiron 5100 Battery http://www.globallaptopbatteries.co.uk/dell/inspiron-5150.htm Dell inspiron 5150 Battery http://www.globallaptopbatteries.co.uk/dell/inspiron-5160.htm Dell inspiron 5160 Battery http://www.globallaptopbatteries.co.uk/dell/inspiron-6000.htm Dell inspiron 6000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9000.htm Hp pavilion dv9000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9500.htm Hp pavilion dv9500 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9600.htm Hp pavilion dv9600 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9700.htm Hp pavilion dv9700 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-tx1000.htm Hp pavilion tx1000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9000.htm HP pavilion dv9000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9700.htm HP pavilion dv9700 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9500.htm HP pavilion dv9500 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9600.htm HP pavilion dv9600 Battery http://www.globallaptopbatteries.co.uk/hp/mini-1001.htm HP mini 1001 Battery http://www.globallaptopbatteries.co.uk/hp/mini-1000.htm HP mini 1000 Battery http://www.globallaptopbatteries.co.uk/hp/mini-1050.htm HP mini 1050 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv2000.htm HP pavilion dv2000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv6000.htm HP pavilion dv6000 Battery http://www.globallaptopbatteries.co.uk/hp/pavilion-dv9000.htm HP pavilion dv9000 Battery http://www.globallaptopbatteries.co.uk/hp/mini-1001.htm HP mini 1001 Battery http://www.globallaptopbatteries.co.uk/hp/hstnn-db02.htm Hp hstnn-db02 Battery http://www.globallaptopbatteries.co.uk/hp/hstnn-ib04.htm Hp hstnn-ib04 Battery http://www.globallaptopbatteries.co.uk/hp/hstnn-ub02.htm Hp hstnn-ub02 Battery http://www.globallaptopbatteries.co.uk/acer/aspire-2420-series.htm Acer aspire 2420 series Battery http://www.globallaptopbatteries.co.uk/acer/aspire-3600.htm Acer aspire 3600 Battery http://www.globallaptopbatteries.co.uk/acer/aspire-3610.htm Acer aspire 3610 Battery http://www.globallaptopbatteries.co.uk/acer/aspire-3680.htm Acer aspire 3680 Battery http://www.globallaptopbatteries.co.uk/acer/aspire-5050.htm Acer aspire 5050 Battery http://www.globallaptopbatteries.co.uk/acer/aspire-5080.htm Acer aspire 5080 Battery

  3. Unknown says:

    http://www.akkuliste.com/toshiba/pa3451u.htm toshiba pa3451u akku http://www.akkuliste.com/toshiba/pa3457u.htm toshiba pa3457u akku http://www.akkuliste.com/toshiba/satellite-a80.htm toshiba satellite a80 akku http://www.akkuliste.com/toshiba/satellite-a85.htm toshiba satellite a85 akku http://www.akkuliste.com/toshiba/pa3465u-1brs.htm toshiba pa3465u-1brs akku http://www.akkuliste.com/toshiba/pabas069.htm toshiba pabas069 akku http://www.akkuliste.com/toshiba/pa3536u.htm toshiba pa3536u akku http://www.akkuliste.com/toshiba/satellite-x200.htm toshiba satellite x200 akku http://www.akkuliste.com/toshiba/pa3536u-1brs.htm toshiba pa3536u-1brs akku http://www.akkuliste.com/toshiba/satellite-p200.htm toshiba satellite p200 akku http://www.akkuliste.com/toshiba/satellite-p205.htm toshiba satellite p205 akku http://www.akkuliste.com/toshiba/pa3534u-1brs.htm toshiba pa3534u-1brs akku http://www.akkuliste.com/toshiba/satellite-a205.htm toshiba satellite a205 akku http://www.akkuliste.com/uniwill/255-3s4400-g1l1.htm uniwill 255-3s4400-g1l1 akku http://www.akkuliste.com/uniwill/un255.htm uniwill un255 akku http://www.akkuliste.com/uniwill/un258.htm uniwill un258 akku http://www.akkuliste.com/uniwill/258-4s4400-s1p1.htm uniwill 258-4s4400-s1p1 akku http://www.akkuliste.com/uniwill/258-4s4400-s2m1.htm uniwill 258-4s4400-s2m1 akku http://www.akkuliste.com/hp/mini-1000.htm hp mini 1000 akku http://www.akkuliste.com/acer/2420.php acer BTP-ARJ1 2420 series http://www.akkuliste.com/acer/as07b72-akku.php akku Fit Aspire 5520 5920 Series AS07B72 http://www.akkuliste.com/acer/batcl50l.php acer travelmate 290 291 29x 292 batcl50l http://www.akkuliste.com/acer/batecq60.php acer 1800 series batecq60 http://www.akkuliste.com/acer/batefl50l6c40-akku.php akku für Aspire 5030 5050 5500 5550 5570 5580 http://www.akkuliste.com/acer/btp-550.php acer btp-550p btp-550 bat30n3l batby27l http://www.akkuliste.com/acer/btp-agd1.php acer btp-63d1 btp-agd1 3020 3610 http://www.akkuliste.com/acer/lcbtp03003.php New akku fit Acer LIP-4084QUPC SQU-401 5000 http://www.akkuliste.com/acer/tm3200e.php notebook akku für 3UR18650F-3-QC151 tm3200 http://www.akkuliste.com/acer/tm4200.php akku ACER BATBL50L6 Travelmate 4200 4203 4230 4260 4280 http://www.akkuliste.com/acer/um08a71.php Black akku für Acer Aspire One UM08A71 UM08A72 UM08A73 NEW http://www.akkuliste.com/acer/um08a72.php Blue akku für Acer Aspire One UM08B71 UM08B72 UM08B73 NEW http://www.akkuliste.com/acer/um08a73.php white akku für Acer Aspire One ZG5 NEW http://www.akkuliste.com/acer/um08a74.php Black akku für Aspire One A110 NEW http://www.akkuliste.com/acer/um08b72.php Blue akku für Acer Aspire One 150L NEW http://www.akkuliste.com/acer/um08b73.php white akku für Acer Aspire One 150X NEW http://www.akkuliste.com/apple/a1022.php apple powerbook g4 a1022 a1079 m9324 http://www.akkuliste.com/apple/a1078.php apple a1045 a1078 e68043 m9325 m9756 http://www.akkuliste.com/apple/a1175.php apple A1175 Macbook Pro 15-4 http://www.akkuliste.com/apple/a1185.php NEW Hi-Cap 5500mAh akku für MacBook 13 A1185 WHITE http://www.akkuliste.com/apple/a1185-2.php NEW Hi-Cap 5500mAh akku für MacBook 13 A1185 black http://www.akkuliste.com/asus/90-n901b1000.php asus W1 W1000 A42-W1 W1G W1Ga http://www.akkuliste.com/asus/a42-w1.php asus W1 W1000 A42-W1 W1G W1Ga http://www.akkuliste.com/asus/90-nca1b2000.php asus A42-W3 W3A W3N W3V W3000 W3000A grey http://www.akkuliste.com/asus/a3000.php asus a42-a3 a3000 z9100 a3l a3n http://www.akkuliste.com/toshiba/pa3451u.htm toshiba pa3452u akku

  4. Unknown says:

    http://www.batterylaptoppower.com/mitac/bp-8050.htm mitac bp-8050 battery http://www.batterylaptoppower.com/mitac/8375.htm mitac 8375 battery http://www.batterylaptoppower.com/mitac/e2000.htm mitac e2000 battery http://www.batterylaptoppower.com/mitac/8×75.htm mitac 8×75 battery http://www.batterylaptoppower.com/mitac/8575.htm mitac 8575 battery http://www.batterylaptoppower.com/mitac/bp-8089.htm mitac bp-8089 battery http://www.batterylaptoppower.com/mitac/bp-8089x.htm mitac bp-8089x battery http://www.batterylaptoppower.com/mitac/bp-8389.htm mitac bp-8389 battery http://www.batterylaptoppower.com/mitac/bp-8089p.htm mitac bp-8089p battery http://www.batterylaptoppower.com/mitac/e680.htm mitac e680 battery http://www.batterylaptoppower.com/mitac/bp-8×99.htm mitac bp-8×99 battery http://www.batterylaptoppower.com/mitac/bp-8599.htm mitac bp-8599 battery http://www.batterylaptoppower.com/nec/op-570-75303.htm nec op-570-75303 battery http://www.batterylaptoppower.com/nec/pc-vp-wp25.htm nec pc-vp-wp25 battery http://www.batterylaptoppower.com/nec/pc-vp-wp44.htm nec pc-vp-wp44 battery http://www.batterylaptoppower.com/nec/op-570-75901.htm nec op-570-75901 battery http://www.batterylaptoppower.com/nec/m300.htm nec m300 battery http://www.batterylaptoppower.com/nec/m500.htm nec m500 battery http://www.batterylaptoppower.com/sony/pcga-bp2s.htm sony pcga-bp2s battery http://www.batterylaptoppower.com/sony/pcga-bp2t.htm sony pcga-bp2t battery http://www.batterylaptoppower.com/sony/pcga-bp3t.htm sony pcga-bp3t battery http://www.batterylaptoppower.com/sony/pcg-tr3.htm sony pcg-tr3 battery http://www.batterylaptoppower.com/sony/pcg-tr2.htm sony pcg-tr2 battery http://www.batterylaptoppower.com/sony/pcg-tr1.htm sony pcg-tr1 battery http://www.batterylaptoppower.com/sony/pcga-bp2v.htm sony pcga-bp2v battery http://www.batterylaptoppower.com/sony/pcg-z1.htm sony pcg-z1 battery http://www.batterylaptoppower.com/sony/pcg-v505.htm sony pcg-v505 battery http://www.batterylaptoppower.com/sony/pcga-bp2e.htm sony pcga-bp2e battery http://www.batterylaptoppower.com/sony/vgp-bp2ea.htm sony vgp-bp2ea battery http://www.batterylaptoppower.com/sony/pcg-gr100.htm sony pcg-gr100 battery http://www.batterylaptoppower.com/sony/pcg-gr150.htm sony pcg-gr150 battery http://www.batterylaptoppower.com/sony/pcg-gr250.htm sony pcg-gr250 battery http://www.batterylaptoppower.com/sony/pcg-gr270.htm sony pcg-gr270 battery http://www.batterylaptoppower.com/sony/vgp-bps2a.htm sony vgp-bps2a battery http://www.batterylaptoppower.com/sony/vgp-bps2b.htm sony vgp-bps2b battery http://www.batterylaptoppower.com/sony/vgp-bps2.htm sony vgp-bps2 battery http://www.batterylaptoppower.com/sony/vgp-bps2b.htm sony vgp-bps2b battery http://www.batterylaptoppower.com/sony/vgp-bps2c.htm sony vgp-bps2c battery http://www.batterylaptoppower.com/sony/vgp-bpl2c.htm sony vgp-bpl2c battery http://www.batterylaptoppower.com/toshiba/b404.htm toshiba b404 battery http://www.batterylaptoppower.com/toshiba/ba1405.htm toshiba ba1405 battery http://www.batterylaptoppower.com/toshiba/pa2487.htm toshiba pa2487 battery http://www.batterylaptoppower.com/toshiba/pa2487urg.htm toshiba pa2487urg battery http://www.batterylaptoppower.com/toshiba/pa3107u-1brs.htm toshiba pa3107u-1brs battery http://www.batterylaptoppower.com/toshiba/1800.htm toshiba 1800 battery

  5. Unknown says:

    http://www.adapterlist.com/dell/d400.htm dell d400 battery http://www.adapterlist.com/dell/latitude-d400.htm dell latitude d400 battery http://www.adapterlist.com/dell/original-inspiron-1525.htm dell original inspiron 1525 battery http://www.adapterlist.com/dell/original-inspiron-1526.htm dell original inspiron 1526 battery http://www.adapterlist.com/dell/latitude-d810.htm dell latitude d810 battery http://www.adapterlist.com/dell/precision-m70.htm dell precision m70 battery http://www.adapterlist.com/dell/y4367.htm dell y4367 battery http://www.adapterlist.com/dell/inspiron-1100-series.htm dell inspiron 1100 series battery http://www.adapterlist.com/dell/inspiron-1150.htm dell inspiron 1150 battery http://www.adapterlist.com/dell/inspiron-5150.htm dell inspiron 5150 battery http://www.adapterlist.com/dell/inspiron-5100.htm dell inspiron 5100 battery http://www.adapterlist.com/dell/inspiron-1000.htm dell inspiron 1000 battery http://www.adapterlist.com/dell/inspiron-1200.htm dell inspiron 1200 battery http://www.adapterlist.com/dell/inspiron-2200.htm dell inspiron 2200 battery http://www.adapterlist.com/dell/e1405.htm dell e1405 battery http://www.adapterlist.com/dell/inspiron-630m.htm dell inspiron 630m battery http://www.adapterlist.com/dell/inspiron-640m.htm dell inspiron 640m battery http://www.adapterlist.com/dell/xps-m140.htm dell xps m140 battery http://www.adapterlist.com/dell/xps-1330.htm dell xps 1330 battery http://www.adapterlist.com/dell/xps-m1330.htm dell xps m1330 battery http://www.adapterlist.com/dell/inspiron-6400.htm dell inspiron 6400 battery http://www.adapterlist.com/dell/latitude-131l.htm dell latitude 131l battery http://www.adapterlist.com/dell/vostro-1000.htm dell vostro 1000 battery http://www.adapterlist.com/dell/1501.htm dell 1501 battery http://www.adapterlist.com/dell/e1505.htm dell e1505 battery http://www.adapterlist.com/dell/kd476.htm dell kd476 battery http://www.adapterlist.com/dell/gd761.htm dell gd761 battery http://www.adapterlist.com/dell/312-0273.htm dell 312-0273 battery http://www.adapterlist.com/dell/312-0417.htm dell 312-0417 battery http://www.adapterlist.com/dell/451-10180.htm dell 451-10180 battery http://www.adapterlist.com/dell/c2174.htm dell c2174 battery http://www.adapterlist.com/dell/f1244.htm dell f1244 battery http://www.adapterlist.com/dell/g1947.htm dell g1947 battery http://www.adapterlist.com/dell/h5559.htm dell h5559 battery http://www.adapterlist.com/dell/hj424.htm dell hj424 battery http://www.adapterlist.com/dell/inspiron-9100.htm dell inspiron 9100 battery http://www.adapterlist.com/dell/dell-inspiron-xps.htm dell dell inspiron xps battery http://www.adapterlist.com/dell/inspiron-2000.htm dell inspiron 2000 battery http://www.adapterlist.com/dell/inspiron-2100.htm dell inspiron 2100 battery http://www.adapterlist.com/dell/inspiron-2800.htm dell inspiron 2800 battery http://www.adapterlist.com/dell/latitude-ls-400.htm dell latitude ls 400 battery http://www.adapterlist.com/dell/d620.htm dell d620 battery http://www.adapterlist.com/dell/d630.htm dell d630 battery http://www.adapterlist.com/dell/latitude-d620.htm dell latitude d620 battery http://www.adapterlist.com/dell/latitude-d820.htm dell latitude d820 battery http://www.adapterlist.com/dell/latitude-d830.htm dell latitude d830 battery

Comments are closed.