0

I have a c# program that updates a txt file at random time intervals, and a labview program that continuously checks the data in the txt file and checks it.

Can you guide me to a way to avoid collisions between those apps?

M.Babcock
  • 18,753
  • 6
  • 54
  • 84
Mario
  • 1
  • 1
  • So one app is a reader and the other is a writer, correct? Both apps won't write to the file at the same time? – M.Babcock Apr 17 '12 at 14:38
  • yes exactly. c# writes and labview reads, – Mario Apr 17 '12 at 14:52
  • In that case only managing the file locks should be necessary to mitigate any collisions. Unfortunately, I'm not familiar with labview enough to provide a solid answer. I can only suggest looking into any options it provides regarding file locking. – M.Babcock Apr 17 '12 at 15:01
  • @Mario I was not aware Labview was not a C# app. – Raj Ranjhan Apr 17 '12 at 15:06
  • You can use Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645) to find out what type of share labview is using when it opens the file. – Polyfun Apr 17 '12 at 15:13
  • Communication between processes via text file is awkward and may lead to bad surprises, you should consider better inter-process communication stuff, like pipes or sockets – CharlesB Apr 17 '12 at 22:19

2 Answers2

1

LabVIEW has a deny access-vi. So you could block C# from writing while it reads. http://zone.ni.com/reference/en-XX/help/371361E-01/glang/lock_range/ (Deny access - Read - Allow access)

I'd do the writing in C# with a try-catch loop, or something like that - but I'm no C#-expert.

Birgit P.
  • 396
  • 2
  • 6
0

One simple way is to use a named/global mutex

http://msdn.microsoft.com/en-us/library/f55ddskf.aspx

Mutex's with the same name are seen as the same by all processes. You can use them to signal or lock.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • Probably is not necessary, as one program is a writer, and the other one seems to be a reader, so both progams should be able to access the same file at the same time, as long as the correct FileShares are used. – Polyfun Apr 17 '12 at 14:50