c# - Why Invoke is needed? -


i kinda understand point of threads , invokes, not great. i'm having server/client application made tutorial. i'm having 2 functions. in disconnect function need have invoke in received function don't.

why (problem lstclient) ?

and if have invoke in received function invoke looping reason, why?

void client_disconnected(client sender) {     invoke((methodinvoker)delegate     {         (int = 0; < lstclient.items.count; i++)         {             client client = lstclient.items[i].tag client;             if(client.id == sender.id)             {                 lb_id.items.removeat(i); lb_ip.items.removeat(i); lb_users.items.removeat(i);                 lstclient.items.removeat(i);                 break;             }         }     }); }  void client_received(client sender, byte[] data) {     /*invoke((methodinvoker)delegate     {*/         (int = 0; < lstclient.items.count; i++)         {             client client = lstclient.items[i].tag client;             if (client.id == sender.id)             {                 if (encoding.default.getstring(data) == "end")                  {                     client_disconnected(client);                      break;                 }                 lstclient.items[i].subitems[2].text = encoding.default.getstring(data);                 lstclient.items[i].subitems[3].text = datetime.now.tostring() ;                 break;             }         }     //}); } 

it depends on how method called.

there property invokerequired property on objects (controls) can used selectively invoke when needed.

in winforms application, method changes form have run within form ui thread avoid conflicts method makes no changes safely called without invoke partial results.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -