Getting unable to find specified file error

Sunil A M 171 Reputation points
2023-09-04T10:59:34.2333333+00:00

Hi Team,

I am writing below code to share the data across the multiple instances of the same application

.Writing

User's image

Reading

User's image

Getting below exception in line using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Demo",MemoryMappedFileRights.FullControl)).

User's image

PLease help me to read the data here.

Best Regards,

Sunil

Windows development | Windows App SDK
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2023-09-04T18:40:47.3933333+00:00

    Try to keep the Memory-Mapped File open. For example, if the first program is a console, then add a ReadLine, or use a breakpoint:

    using( MemoryMappedFile memoryMappedFile = MemoryMappedFile.CreateFromFile. . . )
    {
        . . .
        Console.ReadLine();
    }
    

    When it stops at ReadLine, check the second program.

    In the real programs, you should probably wait until the second program is terminated.


  2. Castorix31 90,681 Reputation points
    2023-09-05T13:39:28.41+00:00

    I just converted the VB sample I had posted at https://learn.microsoft.com/en-us/answers/questions/594919/how-do-i-share-specific-pieces-of-information-betw?page=2 into WinUI 3 / C#

    and it works on my OS (Windows 10 22H2) :

    WinUI3_MMF


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.