I have an c# application which owns 2 threads. One thread is creating an object while the same object is being used in the second thread. Most of the time it works fine but some time it gives and error Object is in use currently elsewhere.
How to make it possible for threads to use object at same time?
Thanks
Edit
I am accessing a Bitmap object. One thread is creating this bitmap from a stream, displaying it on PictureBox and the second thread is again converting this Bitmap to Byte and transmitting it on the network.
Your basic approach would be a locking object (in a 1-1 relation with the shared object) and a
lockstatement:After the Edit
If you are converting the Bitmap in any way it is probably better to forget about Parallel. It is a complicated class with its own internal locking.
If you don’t convert, then don’t use the bitmap. It will be easier (not trivial) to fork the incoming stream for PictureBox and outgoing stream.