access violation when when writing to files

0

I am writing multiple files at the same time in c#. I am composing videos of multiple photos and saving them asyncronously in files in the same folder. It can happen that there could be 2-3 savings at the same time. Sometimes after a few savings the program crashes and i get:

The program '...' has exited with code -1073741819 (0xc0000005) 'Access violation'.

 if (images % framesPerIO == 0 )
        {
            MediaComposition clone = composition.Clone();
            int videoNumber = images / framesPerIO;
            Debug.WriteLine("Reseting clip from" +videoNumber.ToString());
            composition = new MediaComposition();
            CreateVideo(videoNumber, clone);     
        }

private async Task CreateVideo(int videoNumber, MediaComposition clone)
    {


        Debug.WriteLine("Creating xml"+videoNumber.ToString());
            StorageFile video = await storageFolder.CreateFileAsync("video" + videoNumber.ToString() + ".xml", CreationCollisionOption.ReplaceExisting);
            Debug.WriteLine("xml Created" + videoNumber.ToString());


            DateTime now = DateTime.Now;
            Debug.WriteLine("SavingAsync XML " + video.DisplayName);
            await clips.SaveAsync(video);
            Debug.WriteLine("SavedAsync "+video.DisplayName + (DateTime.Now - now).ToString());


    }

Now, I have 2 questions:

  1. Can i do a breakpoint to see to find out where in the code does the problem happens?
  2. Can it be that the access violation happens because there is no consecutive memory on disk, since another thread starts creating a new file? If so, how can I fix it?
c#
asynchronous
io
file-writing
hololens
asked on Stack Overflow Jul 6, 2018 by Mediarea • edited Jul 9, 2018 by Mediarea

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0