c# - Thread safe file access -


i have program large number of comparisons. compares specific .dat file saved on local machine large number of other files generated on run-time. right unable perform these comparisons using multiple threads because of many system.accessviolationexception. i'm assuming because multiple threads trying access same local file @ same time. how can overcome these comparisons multiple threads?

there several possible reasons access violation:

  1. multiple threads exclusively locking specific .dat file
  2. your multi-threading buggy in regard multiple threads try read same runtime generated file
  3. your multi-threading buggy in regard threads try read runtime generated files before have been generated completely

the following solutions exist:

  1. read .dat file memory once , share data between threads. reduces i/o load
  2. make sure every runtime generated file compared 1 thread. can achieved thread safe queue contains files need compared , shared between threads.
  3. make sure runtime generated file gets known reading threads after has been created completely. can achieved creating in different directory on same disk , moving target directory putting file name queue solution 2 after creation completed.

as matthew watson correctly points out, accessviolationexception caused errors in unmanaged code, not caused multiple threads trying access same file.
answer therefore assumes getting unauthorizedaccessexception.
if not case , indeed getting accessviolationexception problem lies elsewhere.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -