写入文件时发生访问冲突

时间:2018-07-06 13:36:44

标签: c# asynchronous io file-writing hololens

我正在用c#同时写入多个文件。 我正在合成多张照片的视频,并将它们异步保存在同一文件夹中的文件中。 可能同时发生2-3次节省。 有时经过几次保存后,程序崩溃了,我得到了:

  

程序'...'已退出,代码为-1073741819(0xc0000005)   “访问冲突”。

 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());


    }

现在,我有两个问题:

  1. 我可以做一个断点看看代码中的什么地方吗 问题发生了吗?
  2. 是否可能发生访问冲突 因为磁盘上没有连续的内存,因为另一个线程 开始创建一个新文件?如果是这样,我该如何解决?

0 个答案:

没有答案
相关问题