|
|
Hi
I want to write a message to the text file as soon as the server starts.I have written the following code which creates a new file but it does not write anything into it.I tested this code by starting only one server.It does not work.Please help me find where i went wrong.proclist contains the list of all servers.
foreach (Process pr in proclist)
{
if (!File.Exists("logfile.txt"))
{
stw = new StreamWriter("logfile.txt");
}
else
{
stw = File.AppendText("logfile.txt");
}
DateTime started = pr.StartTime;
stw.WriteLine("Server information:");
stw.WriteLine(started.ToString());
}
|
|
|
|
|
Hi,
stw.Close(); ??
or possibly
stw.Flush();
stw.Close();
Although it might be simpler to forget the StreamWriter and use
File.AppendAllText("logfile.txt", String.Format("Server Info:\r\n {0}\r\n", started));
Alan.
|
|
|
|
|
Yes it seems like Flush() is missing.
But for logging you should better use log4net[^].
It is very easy to configure and start writing log messages.
Vitaliy Tsvayer
Tikle
|
|
|
|
|
hi
Thanks now im getting it right
|
|
|
|
|
hello everybody
i need to build a small program in C# that searches within a C source code (a txt file basically) for variables and method names and after that to replace them with something else. i can't do the first part. i've tried to do something but with no success. can you help me with some informations/suggestions?
thank you in advance
|
|
|
|
|
You must know all the keywords that can come before a variable or method name, like int, string etc. You will also need to check if the word there for variable declaration and elsewhere. ie word string might come in a comment text and then you will end up editing the comment.
All I can suggest is to make sure you know what I have written above. Then you can just take the very next word and replace it.
जय हिंद
|
|
|
|
|
list the possible keywords, and try building a regular expression for them, since every line should end with ";" it might loosen writing the a regular expression for it, but it will be a lil tough.
good luck
|
|
|
|
|
When I populate properties in my classes, I usually use reflection to get values from a DataReader and set the values. What do you guys think of this technique? Below is a snipplet:
SqlDataReader dr = new SqlDataReader();
PropertyInfo[] properties = this.GetType().GetProperties();
dr.Read();
foreach (PropertyInfo pf in properties)
{
pf.SetValue(this, dr[pf.Name], null);
}
|
|
|
|
|
Fayu wrote: What do you guys think of this technique?
It's brilliant. Have you applied for a patten yet?
|
|
|
|
|
Thanks. I have been using this technique for many many years now. I always wondered if there was a performance penalty or other types of penalties when using this method. I never encountered any problems. I wanted to see what the experts had to say.
|
|
|
|
|
Fayu wrote: I wanted to see what the experts had to say.
No you don't, that's twittering garbage. If your statement was true you would be reading the Microsoft Documentation rather than posting your garbage in internet forums.
|
|
|
|
|
If you think my posting is garbage, you did not have to respond.
|
|
|
|
|
Fayu wrote: you did not have to respond.
How do you know what I have to do? Oh right, you're one of those guys that just knows stuff huh?
|
|
|
|
|
I think this is a bit odd, and reflection is generally quite slow
|
|
|
|
|
Fayu wrote: What do you guys think of this technique?
Not sure. Why would you do it this way? Does it offers something good?
जय हिंद
|
|
|
|
|
I used this in a base class. When I inherited the base class in other classes, I did not have to worry about populating their properties (or performing other logic), the base class would do it. The other classes that inherited the base class were 'templates'.
|
|
|
|
|
I've done something similar as a learning exercise. Property names and values are read from an encrypted XML file, and I create it entirely using LINQ. It's actually remarkably elegant
|
|
|
|
|
That's fairly dreadful. Better to have a constructor (or initializer) that takes a DataReader and populates itself.
I don't see much point in having a class use Reflection to discover its own properties. Particularly if it's a base class discovering information about classes that derive from it. That's a big no-no.
But if you insist on doing this; I would make one library method (perhaps an Extension Method) that takes both the object to set and the DataReader; and I would not have it use Reflection on each call, I would have it cache the PropertyInfo array the first time it encounters a class and then use the cache thereafter.
|
|
|
|
|
Hi there ,i am developing a game in which i want to use A*(A-star ) Algorithm for the enmey to detect the player position on the basis of the values on the data bases in which there are 5 attributes (left ,right ,up,down ,current).they have the zero value if it can not move to that direction
e.g left =0,right=2,up=3,down=0, current=1, if it moves to right then the current value becomes the 2 .
the problem i am having regarding the A-star algo is what is going to be heuristic h for it in F=g+h.how it going to be calculated what will be the critria for it.
thanks in Advance,
|
|
|
|
|
Why do you choose to put your post on this forum?
Why dont you try posting on a relevant forum like GameDev.Net forums[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
thanxs for ur suggestion i will try this too.
|
|
|
|
|
hai all,
We have taken a Public IP ,we have to create a folder through windows application in that remote system with this Public IP?
we tried this like :
DirectoryInfo Dir = new DirectoryInfo(@"//" + path + "/Main Folder/Sub Folder/");
if (!Dir.Exists)
{
Dir.Create();
}
we got this bellow error :
"The Net work path was not found "
|
|
|
|
|
do you have the network credential to creat a folder there? ... ???
|
|
|
|
|
Hi,
How can i draw a rectangle and ellipes in a user control or in a bitmap without erasing the background, also i need to able to change the thickness and color.
Can i get a simple exapmle?
Thankyou
YPKI
|
|
|
|