|
Hello. I have a big problem with network streams.
I have a network stream and, from time-to-time i have to check from messages received from the server.
My problem is that if i receive, for example, 2 messages from the server if I run in debug mode and stop just before the read, it reads both messages received. But if i run in release mode, i get only the first command(because there is a a small period of time between the two messages where stream.DataAvailable is set to false and it exits my loop).
How can I fix this problem? Because I don't know in advance how many messages the server will send.
This is my code:
<br />
if (stream.CanRead)<br />
{<br />
while (stream.DataAvailable)<br />
{<br />
numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length);<br />
myCompleteMessage = String.Concat(myCompleteMessage, Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead)); <br />
}<br />
} <br />
CAN SOMEONE PLEASE HELP ME???
IT'S A B IG PROBLEM FOR ME, I'M NEW IN C#
THANKS IN ADVANCE!!
|
|
|
|
|
I think you're better of building an Asynchronous Client Socket[^]
It involves a little more code, but it results in a more responsive application and it's easier to extend in the end.
WM.
What about weapons of mass-construction?
"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
|
|
|
|
|
I have an assembly file..
How I can find out(in run time) the assembly is COM server or not
(It's not registered by regasm.)?
Thanks.
|
|
|
|
|
Hello everyone,
I am developing a windows application in which it contains a ListView. I am showing the contents(rows) of the ListView from a csv file where each row represents a different data. I wish to have the ability of deleting any selected row. It appears the only options that I am getting from Streaming is "streamWriter.WriteLine" and "streamReader.ReadLine".
My finding so far is that the only way to delete a row from a text-based file is to rewrite that file without the particular row you want removed. So, I should delete the file, loop through the remaining rows in the ListView, and write them back out one by one. This is not something which I wish to do and I was wondering if there is any better way to get this done?
Can anyone be kind enough to tell how I can get this done?
Thank you very much and have a great day.
Khoramdin
-- modified at 3:31 Tuesday 3rd April, 2007
|
|
|
|
|
Unfortunatly what you wan't isn't possible in a normal textfile or a CSV file for that matter.
The best option is to rewrite the whole file, depending on how large the file is.
It's generally not a good idea to use CSV files as the main data source for large quantities of data. Instead you can import the data in a database and keep it there. Then when you need a subset for export, you can always write something to export the data from the database to a CSV file.
WM.
What about weapons of mass-construction?
"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
|
|
|
|
|
Helo Willem,
Thanx for the reply. My online search also led me to come to the same conclusion. The problem is that I am trying to make a Windows Application which requiers the least from the User system. In addition to that this data is going to be available locally even the user is not connected to internet. Therefore, the assumption is that the user has got no database facilities avaiable locally on thier computer and there is no remote database access.
fortunatly, the CSV file is not going to be very large (My estimation is 10Kbit maximum) which If I am not mistaken is not going to effect the respond of the Windows Application.
The only question that comes to my mind is that which way of the followinf I should use for this purpose?
1- Line by line (reading from one file and writing to another, modifying the data on the way).
2- In "bulk" (load everything into memory, modify the data structure, and write it out again).
Thank you very much for your help and have a great day.
Khoramdin
-- modified at 11:40 Tuesday 3rd April, 2007
|
|
|
|
|
Hi all, I am having problems with the following...
When I run the command dataAdapter.Fill(dataSet) i get the following error...
"Fill:SelectCommand.Connection property has not been initialized"
Any ideas why?
Thanks in advance
He who laughs last is a bit on the slow side
|
|
|
|
|
A DataAdapter as to be associated with a Connection, this can be done in several ways, for instance (excerpt from David Sceppa’s ADO.NET book)
string strConn = "Provider=SQLOLEDB;Data Source=(local)\\NetSDK;" +
"Initial Catalog=Northwind;Trusted_Connection=Yes;";
OleDbConnection cn = new OleDbConnection(strConn);
string strSQL = "SELECT CustomerID, CompanyName FROM Customers";
OleDbCommand cmd = new OleDbCommand(strSQL, cn);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I have all that in, but after taking a good look again I realized that I never opened the connection.
Thanks for the quick reply
He who laughs last is a bit on the slow side
|
|
|
|
|
hi
just check the connection once.. i think connection string is not proper
thank u
Suresh.R
|
|
|
|
|
That was the problem, I never opened the connection
He who laughs last is a bit on the slow side
|
|
|
|
|
i don't know how to implement the xmlDOM concept in c# application.please tel me the concept and codings.
nalini
|
|
|
|
|
using System.Xml
That's about it really. The DOM is implimented by the XmlDocument class.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
 Hi Nalini try with this code. I hope this will help you.
<br />
using System;<br />
using System.Xml;<br />
<br />
namespace DomNodeList<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load(@"D:\workjjf\scripts\xml\MajorKeys.xml");
XmlNodeList majorKeyList = doc.SelectNodes(@"/Root/MajorKey");<br />
foreach (XmlNode majorKeyNode in majorKeyList)<br />
{<br />
XmlElement majorElement = majorKeyNode as XmlElement;<br />
string majorAttValue = "<null>";<br />
if (majorElement != null)<br />
{<br />
string attValue = majorElement.GetAttribute("att");<br />
if (attValue != null)<br />
{<br />
majorAttValue = attValue;<br />
}<br />
}<br />
Console.WriteLine(majorAttValue);<br />
XmlNodeList minorKeyList = majorKeyNode.SelectNodes(@"MinorKey");<br />
foreach (XmlNode minorKeyNode in minorKeyList)<br />
{<br />
XmlElement minorElement = minorKeyNode as XmlElement;<br />
string minorAttValue = "<null>";<br />
if (minorElement != null)<br />
{<br />
string attValue2 = minorElement.GetAttribute("att");<br />
if (attValue2 != null)<br />
{<br />
minorAttValue = attValue2;<br />
}<br />
}<br />
Console.WriteLine("\t" + minorAttValue);<br />
XmlNodeList valueList = minorElement.SelectNodes("Value");<br />
foreach (XmlNode valueNode in valueList)<br />
{<br />
Console.WriteLine("\t\t" + valueNode.InnerText);<br />
}<br />
}<br />
}<br />
Console.ReadLine();<br />
}<br />
}<br />
}<br />
Regards,
Satips.
|
|
|
|
|
It's obviously not going to run, you haven't given him the Xml that it's trying to load.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi,
doc.Load(@"D:\workjjf\scripts\xml\MajorKeys.xml");
if the file doesn't exsist how to handle the error and how to create a root node to enter values..
pls help me
with regards
prasad
|
|
|
|
|
hai
i want to splir string and i want keep two parts of that string into 2 string variables
can u plz send me the code in c#
Suresh.R
|
|
|
|
|
Hello,
Use the Split method of the string class.
This will return a string[].
Try and ask again if you need more help.
All the best,
Martin
|
|
|
|
|
hi
string[] str=string.split('');
example:
string s="xxx yyy zzzz";
if u want to split string with whitespace then write this
string[] str=s.split(' ');
i hope this works fine
|
|
|
|
|
Hello shakeela!
The reason why I didn't gave an example in my answer, was the "send me the code in c#" statement in the question.
This is mostely a sign of a "Please do my homework for me, because I don't whant to lose time by thinking myself!" question!
All the best,
Martin
|
|
|
|
|
Hi!
I want to locate main menu control according to my requirement in the middle of the windows form.But i couldnot find location property for that control. I want to ask that can i change its position or it will always be placed at the top of the form.
Thanx
|
|
|
|
|
A menu is ALWAYS on the top of a form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am writing a program that downloads a database on remote laptops, When downloading the file I noticed that my program uses about 15 MB of memory and calls Windows Explorer and WE uses about 16 MB of memory, the database file is about 60MB. I was wondering if there is something i am missing to reduce the amount of memory I am using. the laptops that will be using this app are older laptops and I want this process not to interfere with another database app that is very memory intensive. and once the download is complete it does not release the memory to a reasonable level any ideas.
Thanks
Rob
FileStream fs = null; //' To access the local file;
WebRequest req;
//StreamReader sr;
try
{
// This sets up the Request instance
req = WebRequest.Create("http://www.domian.com/file.zip");
// Use a GET since no data is being sent to the web server
req.Method = "GET";
// This causes the round-trip
WebResponse rsp = req.GetResponse();
try
{
// Open the file to stream in the content
fs = new FileStream("file.zip", FileMode.Create);
// Copy the content from the response stream to the file.
CopyData(rsp.GetResponseStream(), fs);
}
|
|
|
|
|
How exactly are you copying the data from the response stream to the file stream?
Another thing to consider is that looking at memory usage in the Task Manager (which is what I assume you are doing) can often be misleading. The allocated memory listed for a .NET-based application often includes memory which has been collected (i.e. released) as far as the application goes, but which simply hasn't been given back to the system by the runtime. However, that memory can be given back if and when the runtime believes the system needs it.
If there are specific performance (memory or CPU) requirements for your application, then I would suggest using a profiler to help determine where the bottlenecks are in your application.
-Phil
|
|
|
|
|
Hello everyone,
I have a string which I would like to remove the SPACE in the string. For example, I would like to change "I would like to remove any space." into "Iwouldliketoremoveanyspace.".
Can anyone be kind enough to tell me how I can get this done?
Thank you very much and have a great day.
Khoramdin
|
|
|
|