While i'm using the source and testing i have got a console Error tells me that :
The process cannot access the file 'D:\Games\ConquerSource\MINE\AboDiab\5936\bin\Debu g\database\Jianghu.txt' because it's being used by another process.
And it gives me some information like :
Jianghu.cs line 147
Write.cs line 54
But i had ignored this console error.
Unfortunately, When i left the source running for about an hour .. the server stopped and gives me that error.
So you write an empty string to a file, instead of creating it directly. Than, you truncate it and close it ? Than, you write data to it ? Honestly, your code is totally wrong. If you want to overwrite the file, just open it in write mode instead of append. All that can be done with a single stream.
Anyway, I suppose that another process is already locking the file, or that File.WriteAllText is not releasing the handle directly after writing the data.
That little piece of code seems to use 3 file streams to do something you could achieve with one line of code (and one stream) -- already explained by CptSky. If you can't even work with the basic libraries provided to you with full documentation in C#, how do you plan on working on a server with little to no documentation?
@CptSky --> Well, how can i write that code in the standard way?
Or specifically, How can i repair this problem?
i tried alot and already copied the Jianghu.txt from another source then a pasted it to mine, i got the same error!!!
I respect you somehow ^_^.
_________________________________
@nTL3fTy --> Firstly, it's not a published server. Just a local one for me, Just practicing on it.
Secondly, not even your business.
Firstly, some variable names look like what you get when you use ILSpy.
'writer2' isn't even used, did you code this?
You compare bool == bool, and it isn't even File.Exists == true, you define a variable for it (another bad sign of ILSpy).
When using 'using', you shouldn't need to dispose of or close your writers, that's the point of 'using'.
Here is literally all of that in many less lines:
Code:
if (mod == Conquer_Online_Server.Database.Mode.Open)
{
if (File.Exists(this.location))
{
using (var writer = File.OpenWrite(this.location))
{
writer.WriteLine("Count={0}", this.Count);
foreach (var it in this.Items)
writer.WriteLine(it);
}
}
// whatever else you have here....
}
public Write Execute(Mode mod) { if (mod == Mode.Open) { using (SW = new StreamWriter(location, false, Encoding.Default)) { SW.WriteLine("Count=" + Count); for (int x = 0; x < Count; x++) { SW.WriteLine(Items[x]); } SW.Close(); } } else { using (SW = new StreamWriter(File.Create(location))) { SW.WriteLine("Count=" + Count); for (int x = 0; x < Count; x++) { SW.WriteLine(Items[x]); } SW.Close(); } } return this; }
--------------------------
the problem is that ur source save the whole jiang client every entity close.
u need only one save on exit
check the code all reference and u will see
You do realize the point of "using" don't you?! It's to auto initialize and dispose of a disposable object - that includes a StreamWriter. ".Close()" does not need to be called, the end of the "using" block does that automatically.
Also, assuming Items is an array, you should use foreach since you are not using the indexes for anything.
Also, you could condense it more and do:
Code:
using (var SW = (mod == Mode.Open ? new StreamWriter(location, false, Encoding.Default) :
new StreamWriter(File.Create(location))))
and just have 1 loop. Eliminates so many lines of repeated code
You do realize the point of "using" don't you?! It's to auto initialize and dispose of a disposable object - that includes a StreamWriter. ".Close()" does not need to be called, the end of the "using" block does that automatically.
Also, assuming Items is an array, you should use foreach since you are not using the indexes for anything.
Also, you could condense it more and do:
Code:
using (var SW = (mod == Mode.Open ? new StreamWriter(location, false, Encoding.Default) :
new StreamWriter(File.Create(location))))
and just have 1 loop. Eliminates so many lines of repeated code
Edit: Nevermind, I read the code again for what it does, and the style is ... alright. Completely unnecessary though. Not bad style too much, just bad programming.
You do realize the point of "using" don't you?! It's to auto initialize and dispose of a disposable object - that includes a StreamWriter. ".Close()" does not need to be called, the end of the "using" block does that automatically.
Also, assuming Items is an array, you should use foreach since you are not using the indexes for anything.
Also, you could condense it more and do:
Code:
using (var SW = (mod == Mode.Open ? new StreamWriter(location, false, Encoding.Default) :
new StreamWriter(File.Create(location))))
and just have 1 loop. Eliminates so many lines of repeated code
aha i know
just edited the worst part and forget the rest.
public Write Execute(Mode mod) { using (SW = new StreamWriter(location, false, Encoding.Default)) { SW.WriteLine("Count=" + Count); for (int x = 0; x < Count; x++) SW.WriteLine(Items[x]); } return this; }
anyway as said before
the problem isn't from here.
he had to check all the reference that use this
he will find it in a loop when i should recall only 1 time
Quote:
Originally Posted by Spirited
I agree with Yuki. Putting a bunch of equals on one line is really bad style. Try to avoid it at all costs. Line count isn't everything.
Also, why are you still reading the file like that? Just read and write to it asynchronously. But wait - why the hell is it a text file? Why aren't you doing this in SQL? Why flat-file?
'Download des Process File fehlgeschlagen' 06/21/2013 - Elsword - 11 Replies Hallo liebe Community,
ich habe folgendes Problem,von dem ihr vielleicht schon gehört habt,da es ziemlich verbreitet ist:Ich öffne Elsword wie gewohnt und warte bis es zu Ende aktualisiert/geprüft hat.Aber seit gestern ,als ich zum ersten Mal (an diesem Tag) wieder den PC anmachte um Elsword zu spielen,funktionierte Els mehr.
Nach zirka 3Minuten Wartezeit erscheint jedes Mal folgendes Fenster:
http://im.bilderkiste.org/4137184097505/elsword_f ehler.png
Ich habe heute zirka 6 Stunden...
The vb.net command to delete a file in order Process with vb.net. 08/11/2012 - .NET Languages - 0 Replies http://pic.free.in.th/id/8b8cc02259e8ebb9c036e7a7e 8514a71It is a command to delete a file in a vb.net Process Hacke, please help me thank you very much as in me is very difficult. Help it by arrow I in order to be removed.
injecting a file to process? 01/07/2012 - AutoIt - 1 Replies Need help on injecting a file (dds image file) into a process at a specific address.
File Access Denied! 06/02/2011 - Dekaron Private Server - 0 Replies Hey all, I went to put in a new update earlier, but when I pressed "Load files" on the updater thingy, it said "File Access Denied". I pressed "Pack Files" and it says "List index is out of bounds (1). What did I do o.O!?