2014-11-26 2 views
-3

Im 사용 #C.다른 프로세스에서 사용중인 파일

[Henry 2014-11-26 21:10:45] ERROR: System.IO.IOException: Kan geen toegang krijg 
en tot het bestand C:\Users\Jonathan\Desktop\HatBot\Bin\Debug\trades.txt omdat h 
et wordt gebruikt door een ander proces. 
    bij System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
    bij System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, 
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions 
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boole 
an useLongPath, Boolean checkHost) 
    bij System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 

    bij SteamBot.SimpleUserHandler.OnMessage(String message, EChatEntryType type) 
in c:\Users\Jonathan\Desktop\HatBot\SteamBot\SimpleUserHandler.cs:regel 160 
    bij SteamBot.Bot.<HandleSteamMessage>b__9(FriendMsgCallback callback) in c:\U 
sers\Jonathan\Desktop\HatBot\SteamBot\Bot.cs:regel 498 
    bij SteamKit2.CallbackMsg.Handle[T](Action`1 handler) 
    bij SteamBot.Bot.HandleSteamMessage(CallbackMsg msg) in c:\Users\Jonathan\Des 
ktop\HatBot\SteamBot\Bot.cs:regel 488 
    bij SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWo 
rkEventArgs) in c:\Users\Jonathan\Desktop\HatBot\SteamBot\Bot.cs:regel 826 

[Henry 2014-11-26 21:10:45] ERROR: System.IO.IOException: Kan geen toegang krijg 
en tot het bestand C:\Users\Jonathan\Desktop\HatBot\Bin\Debug\trades.txt omdat h 
et wordt gebruikt door een ander proces. 
    bij System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
    bij System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, 
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions 
options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boole 
an useLongPath, Boolean checkHost) 
    bij System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) 

    bij SteamBot.SimpleUserHandler.OnMessage(String message, EChatEntryType type) 
in c:\Users\Jonathan\Desktop\HatBot\SteamBot\SimpleUserHandler.cs:regel 160 
    bij SteamBot.Bot.<HandleSteamMessage>b__9(FriendMsgCallback callback) in c:\U 
sers\Jonathan\Desktop\HatBot\SteamBot\Bot.cs:regel 498 
    bij SteamKit2.CallbackMsg.Handle[T](Action`1 handler) 
    bij SteamBot.Bot.HandleSteamMessage(CallbackMsg msg) in c:\Users\Jonathan\Des 
ktop\HatBot\SteamBot\Bot.cs:regel 488 
    bij SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWo 
rkEventArgs) in c:\Users\Jonathan\Desktop\HatBot\SteamBot\Bot.cs:regel 826 

일 : 내가

TextWriter tw = new StreamWriter("trades.txt"); 
// write a line of text to the file 
tw.WriteLine(DateTime.Now); 
// close the stream 
tw.Close(); 

을 할 경우이 파일이 다른 프로세스에서 사용되는 오류가 발생합니까? 내가 줄 지어 줄 명령을 갖고 싶다. 그러나 이것은이

using System.IO; 
using(FileStream fileStream = new FileStream(@"c:\trades.txt", FileMode.Open)) 
{ 
    fileStream.Write(DateTime.Now.ToString()); 
    fileStream.Flush(); 
} 
+0

는 (은'세척을 발행 시도가 – MethodMan

+0

다른 프로세스가 파일을 잠근 것처럼 보입니다. –

답변

0

이 당신이 일을 다음

string filePath = @"c:\"trades.txt""; 
using (StreamWriter sw = new StreamWriter(filePath, true)) 
{ 
    tw.WriteLine(DateTime.Now.ToString()); 
    tw.Flush(); 
} 

또 다른 방법을 시도 할 수있는 새로운 파일이 있다고 가정하면 ... 점점 오류입니다)`메소드를 코딩하기 전에 .. 또한 당신이 사용하고있는 모든 코드가 ..? 모든 관련 코드를 보여줄뿐만 아니라`using '주위에`TextWriter`를 감싸기 위해 코드를 다시 고려해보기 바랍니다.

관련 문제