2008-10-29 28 views
6

Tôi đang sử dụng FileStream để ghi vào một tập tin và xem các cuộc gọi hệ thống cơ bản sử dụng Process Monitor. Tôi đang gặp sự cố với một số vấn đề về khóa tệp trong triển khai sản xuất, vì vậy tôi đang xem chi tiết chặt chẽ.Ghi vào một FileStream hoạt động lạ, như quan sát bởi quá trình giám sát

Mã này mẫu:

 using (FileStream fs = new FileStream("c:\\temp\\test.txt", FileMode.Create, FileAccess.Write, FileShare.Read)) 
     { 
      fs.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5); 
      fs.Close(); 
     } 

Nguyên nhân các hệ thống sau đây gọi:

9:27:09.4561092 AM ConsoleApplication1.vshost.exe 2320 CreateFile C:\temp\test.txt SUCCESS Desired Access: Generic Read/Write, Disposition: OverwriteIf, Options: Synchronous IO Non-Alert, Non-Directory File, Open No Recall, Attributes: n/a, ShareMode: Read, AllocationSize: 0, OpenResult: Overwritten 
9:27:12.2217409 AM ConsoleApplication1.vshost.exe 2320 WriteFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2219901 AM ConsoleApplication1.vshost.exe 2320 CloseFile C:\temp\test.txt SUCCESS 
9:27:12.2234484 AM ConsoleApplication1.vshost.exe 2320 CreateFile C:\temp\test.txt SUCCESS Desired Access: Generic Read, Write Attributes, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Complete If Oplocked, Random Access, Attributes: N, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 
9:27:12.2248664 AM ConsoleApplication1.vshost.exe 2320 QueryBasicInformationFile C:\temp\test.txt SUCCESS CreationTime: 10/29/2008 9:04:14 AM, LastAccessTime: 10/29/2008 9:27:12 AM, LastWriteTime: 10/29/2008 9:27:12 AM, ChangeTime: 10/29/2008 9:27:12 AM, FileAttributes: A 
9:27:12.2250075 AM ConsoleApplication1.vshost.exe 2320 SetBasicInformationFile C:\temp\test.txt SUCCESS CreationTime: -1, LastAccessTime: -1, LastWriteTime: -1, ChangeTime: -1, FileAttributes: n/a 
9:27:12.2255889 AM ConsoleApplication1.vshost.exe 2320 QueryStandardInformationFile C:\temp\test.txt SUCCESS AllocationSize: 8, EndOfFile: 5, NumberOfLinks: 1, DeletePending: False, Directory: False 
9:27:12.2257571 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2259825 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2261588 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2265161 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 2 
9:27:12.2268237 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2271332 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2272841 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2274779 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2276249 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2278766 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2282577 AM ConsoleApplication1.vshost.exe 2320 ReadFile C:\temp\test.txt SUCCESS Offset: 0, Length: 5 
9:27:12.2284476 AM ConsoleApplication1.vshost.exe 2320 QueryFileInternalInformationFile C:\temp\test.txt SUCCESS IndexNumber: 0x2d000000016b88 
9:27:12.2286183 AM ConsoleApplication1.vshost.exe 2320 CloseFile C:\temp\test.txt SUCCESS 
9:27:12.2288759 AM ConsoleApplication1.vshost.exe 2320 CreateFile C:\temp\test.txt SUCCESS Desired Access: Read Attributes, Write Attributes, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 
9:27:12.2305722 AM ConsoleApplication1.vshost.exe 2320 QueryBasicInformationFile C:\temp\test.txt SUCCESS CreationTime: 10/29/2008 9:04:14 AM, LastAccessTime: 10/29/2008 9:27:12 AM, LastWriteTime: 10/29/2008 9:27:12 AM, ChangeTime: 10/29/2008 9:27:12 AM, FileAttributes: A 
9:27:12.2307379 AM ConsoleApplication1.vshost.exe 2320 CloseFile C:\temp\test.txt SUCCESS 

Ba cuộc gọi IO đầu tiên được dự kiến ​​(tạo, viết, đóng), nhưng quá trình này tiếp tục đọc tập tin một chục lần và liên tục mở và đóng nó lại.

Tôi hiện đã quan sát hành vi này trên Win XP SP2 và Win 2003 x64. Tuy nhiên, máy tính Windows Vista của tôi ở nhà hoạt động như mong đợi (chỉ ba dòng đầu tiên).

Bất kỳ manh mối nào về lý do điều này xảy ra trên các thời gian rảnh không phải của Vista?

Trả lời

6

Một khả năng là bạn đã cài đặt chương trình quét vi rút tự tiêm vào từng quy trình đang chạy?

+0

Trong khi tôi không thể xác nhận điều này, nó có ý nghĩa hoàn hảo. Tôi nghi ngờ rằng sớm nhưng loại bỏ nó do truy cập cho thấy rằng nó đến từ EXE của tôi và không phải là một máy quét virus. Tôi không biết rằng máy quét virus có thể tự tiêm vào trong quá trình của tôi. – TheSoftwareJedi

+0

cũng lưu ý, đó là máy quét vi rút POS nếu cần đọc tệp 11 lần. – TheSoftwareJedi

+0

Mặc dù vậy, đọc của máy quét vi rút có nguồn gốc từ ConsoleApplication1.vshost.exe như thế nào? – configurator

Các vấn đề liên quan