{"id":1050,"date":"2021-08-20T15:20:31","date_gmt":"2021-08-20T12:20:31","guid":{"rendered":"https:\/\/droidapps.cf\/?p=1050"},"modified":"2022-01-14T15:55:06","modified_gmt":"2022-01-14T12:55:06","slug":"file-using-by-another-process-csharp","status":"publish","type":"post","link":"https:\/\/droidhack.org\/?p=1050","title":{"rendered":"\u041e\u0431\u043e\u0439\u0442\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0447\u0442\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u044f\u0442 \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\n    <div class=\"pld-like-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-like-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"1050\" data-trigger-type=\"like\" data-restriction=\"ip\" data-ip-check=\"0\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-up\"><\/i>\n                    <\/a>\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-dislike-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"1050\" data-trigger-type=\"dislike\" data-ip-check=\"0\" data-restriction=\"ip\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-down\"><\/i>\n                    <\/a>\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\n<\/div><\/div>\n\n<p>\u0421\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 &#8212; \u043d\u0443\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0437 \u0441\u0432\u043e\u0435\u0439 \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0441\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u043a\u043e\u0434\u0430 \u0432\u044b\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">string path = @\"C:\\logs\\log.txt\";\r\nvar szr = new StreamReader(path);\r\nvar pa = szr.ReadToEnd();<\/pre>\n<p>\u041a\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0432\u044b\u0434\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">System.IO.IOException: \"The process cannot access the file 'C:\\logs\\log.txt' because it is being used by another process.\"<\/pre>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432 FileStream, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0443\u0436\u043d\u044b\u0439 \u043d\u0430\u043c \u0444\u0430\u0439\u043b.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))\r\nusing (var sr = new StreamReader(fs, Encoding.Default))\r\n{\r\n     var ss = sr.ReadToEnd();\r\n}<\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0442 \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0445\u043e\u0434\u0430.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 &#8212; \u043d\u0443\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u043b\u043e\u0433-\u0444\u0430\u0439\u043b \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0437 \u0441\u0432\u043e\u0435\u0439 \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u0435\u0441\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u043a\u043e\u0434\u0430 \u0432\u044b\u0434\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1052,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/posts\/1050"}],"collection":[{"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/droidhack.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1050"}],"version-history":[{"count":1,"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/posts\/1050\/revisions"}],"predecessor-version":[{"id":1051,"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/posts\/1050\/revisions\/1051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/droidhack.org\/index.php?rest_route=\/wp\/v2\/media\/1052"}],"wp:attachment":[{"href":"https:\/\/droidhack.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/droidhack.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/droidhack.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}