I am dealing a big situation in architecture design flaw in multiple threading. I try to keep my application completely thread safe and avoid conflict with each others.
The problem I was aware was this:
Assume there are two threads, Thread A and Thread B.
Thread A is something that you'll see from Static Void Main method as the only thread.
Thread A create an object that have asynchronous methods of Start/Stop and apply event handling to that object.
When Start method was called in the object from Thread A, it creates a new thread for that object to process the information from object properties or inputs which is Thread B. (In my case, network receiving and sending processes in my own protocol.)
When object in Thread B completed in receiving a new information from the input or property, Thread B invoke the event in the object to pass the data along to Thread A.
The problem is, when the event was invoked, it was managed by Thread B instead. Thread B was suppose to run only on that object to continue to do the processing method, but instead it go through to another object and later have cross threading conflict between Thread A and Thread B when it is suppose to pass an event to Thread A for Thread A alone to handle that new output.
If Thread A is the one that initialize the object and the class it was running on, how come when the event was invoked, it runs on Thread B instead?
I needed Thread B to continue to loop forever and not interrupt the program by passing event information to Thread A.
Please excuse my English and Grammar and thank you for your patience. :-)
[EDIT x4] If you want to get the source code, it is located here: http://fcpfoundation.codeplex.com/ (It is up now.)
You can find the source code in the link above. I'm sorry if my explanation isn't clear. The reason I couldn't make an example code is that it simply too big.