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 otherrunning 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.
please read and follow MicroStation Porgramming forum best practices and also BE communities rules. Plenty of important information is missing in your post (what product do you use, what version, is your application external process or does it implement addin and loaded into MicroStation etc.), which makes it harder to answer.
Adam Levine said:Passing data prom one thread to another
It sounds more like general C# question that is better to disccus e.g. at StackOverflow.
Adam Levine said:now i want that otherrunning threads from the same process will be able to pass data to this windows form or even close it or reopen it.
I am not sure whether I understand it right, but it sounds to me like bad internal architecture design. When WinForm is used, MVP pattern should be use to handle how data is presented and how the form events are processed. Is there is any other thread that e.g. provides data for this form, it has to interact with "model classess", not with the form itself.
Adam Levine said:The Windows form GUI is always in use of the end users
Is it MicroStation WinForm from MicroStation addin (so technically it's a form inherited from adapter and connected to MicroStation host) or it's implemented in some other way?
Adam Levine said:what is the best way to implement it in c# ?
In MicroStation it's quite simple. You did not tell what MicroStation version and what API do you use, but e.g. when COM Interop is used in V8i, everything has to be single threaded (STA), because it's a requirement of COM and also MicroStation. So WinForm presented to a user has to be opened from the same process as the application addin class. But when data are retrieved (from MicroStation, from forms...), it's completely up to you how they will be processed, so you can use e.g. BackgroundWorker (or TPL in CONNECT Edition) to work with it at background. The requirement is that you have to implement thread safe mechanism how data is returned back to MicroStation thread. I am pretty sure examples can be found in Microsoft documentation, at StackOwerflow and primarily in any book discussing multithreading development in C#.
Labyrinth Technology | dev.notes() | cad.point