c# - Sharing a memory map simultaneously between processes -


After overcoming some other difficulties, now I'm stuck with this (probably simple) problem.

My goal:

  • At the same time
  • Many examples of my application are running on the same file and the execution (Read and write)> Solution (What do I have to do): Use memory-mapped files to speed up execution. When the app starts, it tries to call CreateFromFile () (I understand that if the file is already mapped by someone else, it will not do anything, but "handle" back ), Then does the income to do its job on the file. / Li>

The problem is that I try an IOException ( the file is being used by another process ) when another process for CreateFromFile () is first I have done the same and therefore the memory-frame file is not disposed of the object. I can, in principle, use mute and repeat the items using the statement. I can, but it dumps the disc to the material, f The slow performance and is going to defeat the purpose.

What is the probable solution to my problem?

Theoretically, CreateOrOpen () can create a non-permanent file, then if necessary I can dump it on the disk, but I believe there is a better way?

Edit: I think I did not make myself clear that all the instances of the application need to be constantly working on the file, they open it and close the file. Without using it, use it for the next 10, 20, 60 minutes.

Program A)

 

For example, code> static zero main (string [] args) {var mmf = MemoryMappedFile.CreateFromFile ( @ "C: \ Users \ Admin \ Documents \ Visual Studio 2010 \ Projects \ serialize \ serialize \ bin \ Debug \ File.dat", FileMode Open, "Name"); Var accessor = mmf.CreateViewAccessor (); Accessor. Write (5, 'D'); Console.Read (); }

Program B)

  static zero main (string [] args) {var mmf = MemoryMappedFile.CreateFromFile (@ "C: \ Users \ Administrator \ Documents \ Visual Studio 2010 \ Projects \ serialize \ serialize \ bin \ Debug \ File.dat ", FileMode.Open," name "); Var accessor = mmf.CreateViewAccessor (); Accessor. Type (2, 'x'); Console.Read (); }  

I run both at the same time, stop waiting for them for console. Read () . Ideally, they can access the file at the same time (i.e. both can open it after another), but as mentioned above, IOException is happening.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -