2011-05-25 194 views
2

我有一个程序,从一次(3)线程以很高的速率将文件写入网络共享。写入文件卡住网络共享

运行一段时间后(通常很短的时间),其中一些线程卡住了。使用Process Monitor,我可以看到有对WriteFile和CloseFile的调用,它们根本没有答案。

此时,我根本无法关闭进程,即使从任务管理器中将其杀死也无济于事。

有趣的是,托管共享的计算机运行Windows Server 2008(R2)时会发生这种情况。如果我将这些共享移动到Windows 2003计算机上,我不会看到这些问题。另外,如果程序在运行Windows Server 2008的计算机上运行(与共享主机不同),我只会看到此问题。

这是一个快速重现问题的简短程序。在从1到20 MB大小的源目录范围内的文件:

Imports System.IO 
Imports System.Threading 

Module Module1 

    Private m_sourceFiles As FileInfo() 
    Private m_targetDir As String 

    Sub Main(ByVal args As String()) 

    Dim sourceDir As New DirectoryInfo(args(0)) 
    m_sourceFiles = sourceDir.GetFiles() 

    m_targetDir = args(1) 

    For i As Integer = 0 To 2 
     ThreadPool.QueueUserWorkItem(AddressOf DoWork) 
    Next 

    Console.ReadLine() 
    End Sub 

    Private Const BUFFER_SIZE As Integer = (128 * 1024) 

    Private Sub DoWork(ByVal o As Object) 
    Console.WriteLine(Thread.CurrentThread.ManagedThreadId) 
    Dim random As New Random(Thread.CurrentThread.ManagedThreadId) 
    While True 
     Dim fileIndex As Integer = random.Next(m_sourceFiles.Count) 
     Dim sourceFile As FileInfo = m_sourceFiles(fileIndex) 
     Dim input As FileStream = sourceFile.OpenRead 
     Dim targetName As String = sourceFile.Name.Replace(sourceFile.Extension, random.Next(Integer.MaxValue) & sourceFile.Extension) 
     Dim targetPath As String = m_targetDir & "\" & targetName 
     Dim output As FileStream = File.Create(targetPath) 

     Dim bytes() As Byte = New Byte((BUFFER_SIZE) - 1) {} 
     Dim read As Integer = input.Read(bytes, 0, bytes.Length) 
     While read <> 0 
     output.Write(bytes, 0, read) 
     read = input.Read(bytes, 0, bytes.Length) 
     End While 
     output.Flush() 
     output.Close() 
     Console.WriteLine(Thread.CurrentThread.ManagedThreadId & " - " & targetName) 
    End While 
    End Sub 

End Module 
+0

出现这种情况,即使只有一个线程。 – 2011-05-29 06:25:27

回答

2

问题是由赛门铁克杀毒软件引起的。 显然他们不支持2008 R1。

我能够在客户端计算机上禁用SMB 2.0要解决的问题,如所描述here

sc config lanmanworkstation depend= bowser/mrxsmb10/nsi 
sc config mrxsmb20 start= disabled