Autor Beitrag
Namenlosnameless
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Sa 11.09.10 21:01 
Hallo!

Ich habe folgendes Problem mit meinem StreamWriter:

Wenn ich mit:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
File.Create(Application.StartupPath + AusgangsOrdnerPfad);

 StreamWriter SW = new StreamWriter(Application.StartupPath + AusgangsOrdnerPfad);
                SW.WriteLine(Pfad.Text);
                SW.Close();

den StreamWriter instanziere gibt es vorerst keine Probleme erst beim Ausführen des Programms wird an der Zeile:
StreamWriter SW = new StreamWriter(Application.StartupPath + AusgangsOrdnerPfad); folgende Exception ausgelöst:

Der Prozess kann nicht auf die Datei "C:\Users\Christoph S\documents\visual studio 2010\Projects\MusicUpdater1\MusicUpdater1\bin\Debug\Datein\AusgangsOrdner.txt" zugreifen, da sie von einem anderen Prozess verwendet wird.

Eigentlich klare Aussage (dachte ich), zuerst habe ich gesucht welcher Prozess auf dieses, 100%ig existierende, .txt-File zugreift und nichts gefunden, dann dachte ich das es mit irgendeinem Programm das geöffnet ist zutun hat, Fehlanzeige, selbst nach Neustart des Computers ohne Start von irgendeinem Prozess selbe Exception... Ich hab schon geschaut ob eine andere Instanz eines StreamWriters nicht geschlossen wird, genauso kein Fund! Mittlerweile ist mein Verdacht auf das 64Bit-Win7 das ich seit einer Woche nutze.

Gibt es irgendjemanden der ähnliche Probleme hat, oder ist es ein Problem meines Computers?

mfg Namenlosnameless

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
funcry
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 110
Erhaltene Danke: 1

Win7 64, XP 32
C# (VS 2010 EE), Delphi (TD 2006 Win32)
BeitragVerfasst: Sa 11.09.10 21:35 
Zitat:
bin\Debug\Datein\


Kann es sein, dass die Datei als Teil des Projektes, beim Compilieren erstellt/kopiert wird und offen gehalten wird ?
Namenlosnameless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Sa 11.09.10 21:44 
kann sein, aber das ist kein Ordner-SPezifisches Problem die exception wird bei jedem Ordner den ich versuche ausgegeben!

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.09.10 22:17 
Naja, du greifst selbst darauf zu. Ich nehme mal an File.Create gibt dir ein Handle bzw. ein Objekt zurück (siehe Doku, hab nicht geschaut). Und danach versuchst du auf diese bereits offene Datei zuzugreifen.

// EDIT:
Ok, hab mal geschaut, wie vermutet:
msdn.microsoft.com/e...ibrary/d62kzs03.aspx
Du bekommst bereits einen Stream für die Datei zurück, was anderes fände ich auch wenig sinnvoll.

Für diesen Beitrag haben gedankt: Namenlosnameless
Namenlosnameless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: Sa 11.09.10 23:16 
Also wenn ich dich richtig verstanden habe führt die "File.Create()"-Methode einen Prozess auf das erstelle File auf!? Darauß schließe ich das ich mit File.Close das ganze beenden kann?

Danke für die Hilfe jaenicke!

Edit: Ich habe gerade gesehen das die File-Klasse keine CLose Methode bereitstellt ;)

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 11.09.10 23:47 
Zitat:
Edit: Ich habe gerade gesehen das die File-Klasse keine CLose Methode bereitstellt ;)


Aber der Filestream der von File.Create zurückgegeben wird hat eine Dispose Methode. Wo sich dann gleich die Frage stellt wieso du den Stream nicht in den StreamWriter schiebst sondern auf dem File noch einen Stream aufmachst in dem du im den selben Path nochmal gibst.
Namenlosnameless Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 259
Erhaltene Danke: 6

Windows XP Home Edition, Windos Vista
C#
BeitragVerfasst: So 12.09.10 00:07 
so hab ichs jetzt eh gelöst!

_________________
1:<<Life sucks!!>> 2:<< Well okay>> 1: <<Just Yours>> 2:<<Ohmph>>