{"action":"created","issue":{"url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/46","labels_url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/46/comments","events_url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/46/events","html_url":"https://github.com/dokan-dev/dokan-dotnet/issues/46","id":122431279,"number":46,"title":"Multi-threaded ReadFile and C# Streams","user":{"login":"Rambalac","id":7804519,"avatar_url":"https://avatars.githubusercontent.com/u/7804519?v=3","gravatar_id":"","url":"https://api.github.com/users/Rambalac","html_url":"https://github.com/Rambalac","followers_url":"https://api.github.com/users/Rambalac/followers","following_url":"https://api.github.com/users/Rambalac/following{/other_user}","gists_url":"https://api.github.com/users/Rambalac/gists{/gist_id}","starred_url":"https://api.github.com/users/Rambalac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rambalac/subscriptions","organizations_url":"https://api.github.com/users/Rambalac/orgs","repos_url":"https://api.github.com/users/Rambalac/repos","events_url":"https://api.github.com/users/Rambalac/events{/privacy}","received_events_url":"https://api.github.com/users/Rambalac/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-12-16T05:24:55Z","updated_at":"2015-12-28T13:11:26Z","closed_at":null,"body":"Maybe that's not Dokan.Net problem, but I'm not sure how it can be solved reliably and efficiently. \r\n\r\nReadFile has Offset parameter and presumes operation is atomic and buffer will be filled from that file offset even if another thread run ReadFile from different position.\r\n\r\nBut C# Streams have Position and Read separate.\r\n\r\nIn case of Windows Explorer file coping after one CreateFile calls ReadFile from multiple threads. In C# If another thread Stream.Position setter happens between other thread's Stream.Position and Stream.Read you get copied garbage from wrong positions of original file. I believe Mirror also has such problem, just try read files bigger 3Mb (Windows Explorer copy block size is about 500Kb) though in its case Position and Read gap is smaller than in mine.\r\n\r\nFor now I have two workarounds.\r\n1. Create separate Streams for each thread where ReadFile called. Wasting resources.\r\n2. Block on Position set and Read. Bad for efficiency."},"comment":{"url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/comments/167566132","html_url":"https://github.com/dokan-dev/dokan-dotnet/issues/46#issuecomment-167566132","issue_url":"https://api.github.com/repos/dokan-dev/dokan-dotnet/issues/46","id":167566132,"user":{"login":"viciousviper","id":8659792,"avatar_url":"https://avatars.githubusercontent.com/u/8659792?v=3","gravatar_id":"","url":"https://api.github.com/users/viciousviper","html_url":"https://github.com/viciousviper","followers_url":"https://api.github.com/users/viciousviper/followers","following_url":"https://api.github.com/users/viciousviper/following{/other_user}","gists_url":"https://api.github.com/users/viciousviper/gists{/gist_id}","starred_url":"https://api.github.com/users/viciousviper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viciousviper/subscriptions","organizations_url":"https://api.github.com/users/viciousviper/orgs","repos_url":"https://api.github.com/users/viciousviper/repos","events_url":"https://api.github.com/users/viciousviper/events{/privacy}","received_events_url":"https://api.github.com/users/viciousviper/received_events","type":"User","site_admin":false},"created_at":"2015-12-28T13:11:26Z","updated_at":"2015-12-28T13:11:26Z","body":"@Rambalac: Force 32bit sounds wrong.\r\nHowever, if you're referring to the setting named \"Run tests in 32 bit or 64 bit process\" in the \"Hosts\" configuration section of the .testsettings file, then I've found this to be irrelevant for testing from within VS2015, which is what I always do.\r\nMaybe you can improve your results in the mstest console by switching this setting to \"Run tests in 64 bit process on 64 bit machine\"."}}