Solved

Filestream synchronization

Posted on 2011-03-03
2
682 Views
Last Modified: 2012-08-14
Hello Experts,

I have 2 threads that access the same filestream.  How do I synchronize the 2 threads so they don't interfere with each other?  also had would I synchronize if I added more threads.  I think manualResetEvent would work but I'm not quite sure.

Thanks,
OFGemini
0
Comment
Question by:OFGemini
2 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35027842
How do they access the stream? If you are only reading, I don't believe you need synchronization.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35028207
As a generic answer, you create a Shared Object that all the threads can access and then enclose all access to the FileStream in a SyncLock block:
http://msdn.microsoft.com/en-us/library/3a86s51t(VS.71).aspx

    Public Class Sync
        Public Shared MyObject As New Object
    End Class

    ...
        SyncLock Sync.MyObject
            ... do something in here ...
        End SyncLock

As each thread hits the SyncLock block it will attempt to get exclusive access to the object.  If another thread already has it locked then the thread will stop and wait until the object has been released.  Only one thread can have a lock at any given time.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select all rows in datagridview 15 21
Object Oriented Best Practice 5 35
Change data in datatable 8 18
Calling stored proc in EDMX 11 19
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now