|
Hi,
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing:
<br />
public CLogHandler()<br />
{<br />
this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read);<br />
this.m_swLog = new StreamWriter(this.m_fsLog);<br />
if(this.m_swLog != null) this.m_swLog.AutoFlush = true; <br />
}<br />
<br />
pubic WriteLogMessage()<br />
{<br />
if(this.m_swLog != null) this.m_swLog.Write("[" + DateTime.Now.ToString("HH:mm:ss") + "] " + aMsg + Environment.NewLine);<br />
}<br />
One of the requirements is to display the current log file contents in a child form. So, I open the log file for reading like this :
<br />
System.IO.FileStream fs = new FileStream(this.m_strCurrentFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);<br />
System.IO.StreamReader sr = new StreamReader(fs);<br />
<br />
while(sr.Peek() > -1) this.DisplayLogText(sr.ReadLine() + Environment.NewLine);<br />
<br />
fs.Close(); <br />
As you see, when I open the file for writing, I'm granting FileShare.Read, which means other processes can open the file for reading. But when I try to open the file for reading, it gives IOException that the file is being used by another process.
So, how can we write and read to and from a file simultaneously in the same program (ofcourse, without stopping the write process)??
Cheers
CNU
|
|
|
|
|
The title says it all. I need to know if there is anyways to make a "copy" of a reference type.
So basically i want to know if there is a way to make a Reference Type variable act like a value type variable.
Or is the only way copy a reference type is to create a new one and then move all the info out of the old one into the new
Thanks for your help!
|
|
|
|
|
It depends on the class of the variable. Some classes define a constructor that take another instance of the same class as a parameter. There's also a MemberwiseClone method, but note it's a protected method. Take a look at the ICloneable interface too.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
YawgmothIII wrote:
Or is the only way copy a reference type is to create a new one and then move all the info out of the old one into the new
That's how you do it. However, there are many ways to do that,
1. You can use MemberwiseClone.
2. Your object can implement ICloneable, implement the Clone method and do the copying there
3. You can use a nifty trick, serialize and deserialize the object back, you'll get a new copy and .NET handles all the copying for you.
private object Copy(object original)
{
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter fs = new BinaryFormatter(original.GetType());
fs.Serialize(ms, original);
return fs.Deserialize(ms);
}
}
Regards
Senthil
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
3.
As I think he doesn't know serialization very well I would add the info that the class being copied needs to be marked as Serializable or implement the ISerializable interface.
|
|
|
|
|
int intJ = (int) o;
where o is an onject of Integer kind
venkat
|
|
|
|
|
1)To personalize the uninstall icon that is showed in install/uninstall programs, how i can do?
2)I need to make more "xp styled" the install wizard forms, for example the progress-bar is flat style, i want to see the xp one. How? Some button is much big, i want to reduce. how?
3)if i make right-click on the desktop shortcut for my application .exe and i go in property window, i can see the Destination target but the button "Find Destination" is disabled, why?
|
|
|
|
|
1)To personalize the uninstall icon that is showed in install/uninstall programs, how i can do?
You have to provide icon file in setup project properties.
- ashish
|
|
|
|
|
Sasuko wrote:
2)I need to make more "xp styled" the install wizard forms, for example the progress-bar is flat style, i want to see the xp one. How? Some button is much big, i want to reduce. how?
You can do
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
For more information, look here[^].
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
hi i have 2 perform xml parsing of IIS log files using C# can someone plz guide me tht what 2 study for this purpose as i hav to do it within three days and i kno less about C# .if someone can also provide me its relative code plzzzzzzzzzzzzzzzzzzzzzzzzzz.
waitin 4 some positive response very soon.
|
|
|
|
|
|
hi i wanna ask u tht its hard to perform xml parsing of IIS files which are kind of text files but not impossible rite?
it seems tht u hav worked a lot in C# plzzzzzzzzzzzzzzz guide me how 2 do tht n the link which u hav sent i wann ask wat u r tryin 2 do in tht prject but most importantly kindly help me in parsing hope 4 very positive response n very soon.
|
|
|
|
|
|
|
thx for the help that really helped!
|
|
|
|
|
I am trying to get a second response from a Webrequest. The server that I am talking to works as follows.
First here is my code:
string postData = "";
Uri myUri = new Uri("http://208.XXX.XX.XXX:10224/?ReturnAddress=209.XX.XX.XX/recvpost.php");
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(myUri);
h.Method = "POST";
h.ContentType="text/xml";
h.ContentLength=postData.Length;
Stream newStream = h.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
newStream.Close();
WebResponse resp = h.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
string str = reader.ReadLine();
while(str != null)
{
Console.WriteLine(str);
MessageBox.Show( str );
str = reader.ReadLine();
}
resp.Close();
1) Send your request, when received the replay "OK" will be sent.
2) Once the server has the request ready it will send the reply.
3) I am receiving the OK but nothing else.
How do you get secondary responses?
|
|
|
|
|
What do you mean by a second response? Each request can have only one response.
---
b { font-weight: normal; }
|
|
|
|
|
I was told by the server provider to send a Webrequest with the above mentioned header information. When the server receives the request it will send the OK reply, and then break the connection. When it has the reply ready it will call back on the ip address provided in the Uri and send the file noted in the Uri recvpost.php.
Uri myUri = new Uri("http://208.XXX.XX.XXX:10224/?ReturnAddress=209.XX.XX.XX/recvpost.php");
So, I guess I am asking how to I listen for that reply?
|
|
|
|
|
Ok you must be receiving as response code.. you have to receive webresponse stream to get the response form the requested uri.
- ashish
|
|
|
|
|
If you look at my above code snippit isn't that what I am doing?
WebResponse resp = h.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
If you mean something different could you please clarify?
|
|
|
|
|
Then the data will be sent as a request to the php page.
---
b { font-weight: normal; }
|
|
|
|
|
Hi everybody:
I use the following code to display the data in a DataGrid Control:
OleDbConnection con = new OleDbConnection(StrConnectionString);
ad=new OleDbDataAdapter();
ad.SelectCommand = new OleDbCommand(strSQL, con);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(ad);
DataTable tbl=new DataTable("Domains");
ds=new DataSet();
ds.Tables.Add(tbl);
ad.Fill(ds,"Domains");
tbl.PrimaryKey=new DataColumn[]{tbl.Columns["CategoryId"],tbl.Columns["DomainUrl"]};
dv=new DataView(tbl);
Grid.DataSource=dv.Table;
it works fine.
and after that I use
dsTmp=ds.Copy();
make another copy of the data and make some change to the dsTmp.
then I save the data back to db and refresh the Grid control by using:
BindingManagerBase bm=BindingContext[dsTmp,"Domains"];
bm.EndCurrentEdit();
ad.Update(dsTmp.Tables["Domains"]);
dsTmp.AcceptChanges();
RefreshDomains();
dsTmp.Clear();
refresh:
ds.Clear();
ad.Fill(ds,"Domains");
since I don't want the user see the middle result of the data change so I use dsTmp to hold the data and make the change. if I have less data, such as 100 rows or less, the code works very well. But if I have lots of data (1 million rows), there is an exception comes out,and the grid can not be drawed. even I just update 2 rows of the 1 million rows.
also cause the exception happens at the "paint event" (I guess), I can not see which line of code cause the problem!
Does anyone has an idea about it?
Thanks a lot!
Alan shen
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
Is there a way to read an XML file into a dataset with the same format as a .config file? Config files are formatted as such:
<configuration>
<appsettings>
<add key="Clear" value="true">
Is there a way to read an XML file into my program using such keys and values? Thanks in advance.
D
|
|
|
|
|
I've never tried anything like this before.
My aquantance has written an exe file which performs certain tasks in C++. It gets data and performs some very complex algorithms on it to produce certain values.
It's written as a DLL and an EXE right now.
It's not a problem for him to modify the code in whatever way I need.
How can I pass values between my C# application and his C++ application (or DLL).
I'm looking for some VERY basic starting information.
Thanks!
If you have time and feel like contacting me directly, my AIM name is navinineteen.
|
|
|
|
|