C
C#11mo ago
Justdie

Properly start threads with function arguments

I need a thread which has for job to talk to the main program to update a label, so i thought i could just pass the label as an argument to the function, but i wish to know how to properly do it since the stuff i found online either don't show how or are 13 years old.
2 Replies
cap5lut
cap5lut11mo ago
usually nowadays u dont create threads urself anymore but use Tasks to reflect asynchronous behaviour these tasks will be scheduled (usually) on the thread pool (creating threads is quite expensive, so reusing them is better) for graphical UI there is also the thing that they usually allow updates to their components only via their UI thread. synchronization over multiple threads has quite some overhead, thats why there is this limitation. each GUI framework has different means to do that. the whole Task stuff relies on a synchronization context, by default that means that its thrown onto the afore mentioned thread pool. some (if not all) GUI frameworks set their own synchronization context as the default one, so that these tasks are executed on the UI thread. so to give hints how to do it correctly means at least that u have to tell us which GUI framework u r using (winforms, wpf, maui, avalonia are the common ones)
Justdie
JustdieOP11mo ago
I was using gtk3 because it suits my needs the best for linux specificaly, but i found out i could use async and it works pretty great, it was just a test project to make a ui for a timer but its pretty neat
Want results from more Discord servers?
Add your server