Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ JAVA and C# _ Passing Data From One Thread To Another

Posted by: adamlevine Mar 21 2018, 10:32 PM

Passing data prom one thread to another

Hi,
I have created a process that's runing a thread that open some windows form, now i want that other
running threads from the same process will be able to pass data to this windows form or even close it or reopen it.

The Windows form GUI is always in use of the end users so i cant lock.
what is the best way to implement it in c# ? i would like a short example, thanks.

Posted by: jleach Mar 22 2018, 07:01 AM

There's no simple example that can be given: threading (and sharing data between threads) is a complex subject. Especially if that data is mutable - you're working in some ugly territory and there's a fair bit of background theory you should be aware of. Multithreading is rife with pitfalls and subtleties.

I'm not sure which UI framework you're using (WinForms, WPF, Xamarin, etc?), but generally speaking take a look at Invoke and BeginInvoke or Task.Run. There's many other ways to do it, but I do suggest some background reading on general threading concepts so you're not blindly walking into dangerous territory (there's entire books devoted to the subject...).