Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create a memory mapped file in a service?

How to create a memory mapped file in a service?

Scheduled Pinned Locked Moved C#
xmlperformancehelptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    occam
    wrote on last edited by
    #1

    Hi, I'm trying to create a memory mapped file file using

    var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
    

    in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using

    var mmf = MemoryMappedFile.OpenExisting("memMapFile");
    

    leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!

    C P 2 Replies Last reply
    0
    • O occam

      Hi, I'm trying to create a memory mapped file file using

      var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
      

      in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using

      var mmf = MemoryMappedFile.OpenExisting("memMapFile");
      

      leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!

      C Offline
      C Offline
      Ciumac Sergiu
      wrote on last edited by
      #2

      You need to create an inter-process memory map file with MemoryMappedFile.CreateNew method. In this way you'll be able to access it from different processes.

      P O 2 Replies Last reply
      0
      • O occam

        Hi, I'm trying to create a memory mapped file file using

        var mmf = MemoryMappedFile.CreateFromFile(@"C:\\Temp\\XMLFile.xml", FileMode.Open, "memMapFile");
        

        in the OnStart() of the service class. The mmf gets created, but trying to access it from an application using

        var mmf = MemoryMappedFile.OpenExisting("memMapFile");
        

        leads to a FileNotFoundException. When the file is created in an application instead in a service, this works. What am I missing? Thanks for your help!

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Is it a local variable in the method? Or a member of the class?

        O 1 Reply Last reply
        0
        • C Ciumac Sergiu

          You need to create an inter-process memory map file with MemoryMappedFile.CreateNew method. In this way you'll be able to access it from different processes.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Not if he's only accessing it from the Service, not from other processes.

          1 Reply Last reply
          0
          • C Ciumac Sergiu

            You need to create an inter-process memory map file with MemoryMappedFile.CreateNew method. In this way you'll be able to access it from different processes.

            O Offline
            O Offline
            occam
            wrote on last edited by
            #5

            Thanks for your reply Ciumac! I went trough the description of the MemoryMappedFile class, but couldn't figure why MemoryMappedFile.CreateFromFile should deliver a result different than MemoryMappedFile.CreateNew. Nevertheless I tried it out - no success!

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Is it a local variable in the method? Or a member of the class?

              O Offline
              O Offline
              occam
              wrote on last edited by
              #6

              Thanks PIEBALDconsult! It was a local variable. Best regards!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups