文本编写者“由另一个进程使用”错误 [英] Text Writer "used by another process" error

查看:66
本文介绍了文本编写者“由另一个进程使用”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在循环中执行以下代码,每次更改正在读取的文件。代码读取输入文件,擦除标记编码,并将其写入临时文件以供以后使用。它在第一次被调用时工作,但是在循环中的第二次调用中,我在下一行中为我正在写入的文件获得了另一个进程使用错误:

xWrite = My.Computer.FileSystem.OpenTextFileWriter(pFileNameNew,False)



I execute the following code in a loop that changes the file being read each time. The code reads the input file, scrubs the markup coding, and writes it to a temp file for use later. It works the first time it is called, but on the second call in the loop, I get a "used by another process" error for the file I am writing to on the following line:
"xWrite = My.Computer.FileSystem.OpenTextFileWriter(pFileNameNew, False)"

Public Sub ScrubPAC(pacfile As String)
        Dim xRead As System.IO.StreamReader
        Dim xWrite As System.IO.StreamWriter
        Dim sBuf As String
        Dim sTemp As String
        Dim sFileName As String
        Dim pFileNameNew As String

        'Scrub PAC
        currentdir = "C:\SOM Folder\VB Development\SOMBBStatGen\"

        sFileName = pacfile
        pFileNameNew = currentdir & "pbp\WIPPAC.prt"

        'read original pac file
        sTemp = ""
        xRead = IO.File.OpenText(sFileName)
        Do Until xRead.EndOfStream
            sBuf = xRead.ReadLine
            sTemp = sTemp & sBuf & vbCrLf
        Loop

        'remove print codes
        sTemp = Replace(sTemp, "[1]", "")
        sTemp = Replace(sTemp, "[2]", "")

        'Write Clean PAC
        xWrite = My.Computer.FileSystem.OpenTextFileWriter(pFileNameNew, False)
        xWrite.WriteLine(sTemp)
        xWrite.Close()



    End Sub





几个小时以来,我一直在努力解决这个问题吗?



I've been struggling with this for hours, any ideas?

推荐答案

无视,我解决了它,当然我发布了这个问题之后。我在另一个SUB中读取文件后没有关闭文件。
Disregard, I solved it, of course right after I posted the question. I didn't close the file after reading it in another SUB.


这篇关于文本编写者“由另一个进程使用”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆