|
Hello,
I'm using Stream.Read(byte[] buffer, int offset, int count) . Is there an alternative to that method (or a property to set) so that the method won't return until all count is read (or end of stream is reached)? Or should I do something like this:
int n = 0, readCount = 0;
while ((n = myStream.Read(buffer, readCount, countToRead - readCount)) > 0)
readCount += n;
|
|
|
|
|
No, you can't force it to read the number of bytes that you request. You have to use a loop with the Read method if you want to read the entire stream.
You should check if the return value from the method is zero, not only if the total number of bytes has reached the expected. If the stream happens to be smaller than you expect, your code will go into an eternal loop.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yes, I edited the post and checked the return value, probably at the same time you were writing.
Thanks.
|
|
|
|
|
Hi everybody,
my application (A) opens a port 35000. An external application (B) has the possibility to connect
on this port 35000.
If the application A is launched 3-times it opens the port 35000, for the second the port 35001 and so far...
Now i created a little tool to check which ports are open.
a simple loop which increments the Portnumber from 30000 to 30256.
But it takes 1 second for each port, so more than 256 seconds for all these possible ports...
In the loop i make each time a
new IPEndPoint(...
and
new Socket(....
Does it run faster in asynchronous mode?
Big thanks for help
|
|
|
|
|
baerten wrote: Does it run faster in asynchronous mode?
It should, just fire off each request in it's own thread.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Thanks for your reply.
But it should also work in a easier way or not?
All Port Scanner Tools works much faster.
I can only test a port each second, thats very slow
So i open for each port a new thread which executes the work?
Thanks to you
|
|
|
|
|
Yes it should, since each request fires will not wait the previous one to complete, so multi of them will end up in the same time for example, in the addetion, there are two ways now to use asyncrounous calls with sockets now, the old one Begin/End aspect... and the new one which is introduced in .NET Framework 3.5, which is supposed to be faster and holds better performance ideas as well.
Sincerely Samer Abu Rabie
Note: Please remember to rate this post to help others whom reading it.
|
|
|
|
|
How can I change the System partition drive letter using c#.net?
|
|
|
|
|
Even if you could do it in C#, you would have to reboot, and then sh*t will probably hit the fan due to changing the System partition's letter.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Greetings,
I beleive this could be accomplished using Windows APIs, I havnt seen how its done, but almost anything is exist in Windows APIs, and I this case as well as I think.
Sincerely Samer Abu Rabie
Note: Please remember to rate this post to help others whom reading it.
|
|
|
|
|
I was a big Perl programmer and I am still spoiled with the availability of modules provided by cpan.org. I have looked but have yet to find anything even remotely similar for C# code.
What I am looking for is places to download small classes of different things to save me a bit of time making some prototype programs. As a basic example, it would be nice to download a simple html parser that I could then use or enhance, or maybe a simple ftp class. I can't really think of things off the top of my head but hopefully the provides enough information to address my question. Is their any place to get simple code snipets like this? Sure I can get entire programs but at that rate I'd just prefer writing my own rather then sorting through someone elses whole program.
Tnx.
Trixy
|
|
|
|
|
Yeah, it's called the .net framework. It's so big it includes all the kind of stuff many other languages rely on add on modules for.
There are whole namespaces dedicated to HTTP and FTP stuff. A good place to look for guides and snippets on how to use this stuff is MSDN (although it's often easier to search MSDN from google).
Simon
|
|
|
|
|
How can I Display Word Documents in C#
Which control do you offer
Thanks in advance
Hello Friends
|
|
|
|
|
RichTextBox?
Loading signature. Please wait...
|
|
|
|
|
Hi,
Here if your context is Asp.net then do as following
create an iframe
<iframe name="iframedoc" frameborder=2 width=580 height=440 src="title.html"></iframe>
create a link also
<a href="your_doc.doc" target="awindow">Open</a>
clicking this open link will show a command box to save/open document, click open..then document will show in browser
You can also handle this in C# put runat property in <a>
|
|
|
|
|
|
|
File.GetCreationTime might help you if you need to read the newer version.
If you want to know that if two versions differ, then get all the file bytes in strings and compare.
Loading signature. Please wait...
|
|
|
|
|
Hi all,
I need to get the text from a .mht file - only the text that the user sees,
no special charachters, no "=".
so, I need either a code in c# that does that, or a .mht Ifilter that works like that.
I also need the same for .html.
Thanks a lot,
Shira.
|
|
|
|
|
ShiraRK wrote: I need to get
ShiraRK wrote: I need either
ShiraRK wrote: I also need the s
You need a lot more than that!
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
if you have nothing smart to say, don't talk at all
|
|
|
|
|
ShiraRK wrote: I need to get the text from a .mht file
Good, so you read the file in
ShiraRK wrote: only the text that the user sees,
no special charachters, no "=".
so you need to do some manipulation
ShiraRK wrote: I also need the same for .html.
and save it to a web page.
Post the code yuo have and maybe someone will help. Otherwise, what you actually need is RENTACODER.COM, where, for a samll fee, someone will write your code for you.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I coded folowing:
public void PWriteToEventLog(Exception ex)
{
EventLog lLog = new EventLog();
lLog.Source = "Data Access Error... ";
lLog.WriteEntry(ex.Message.ToString());
}
public DataTable PGetDataTable(string vConn, string vStrSQL, string vTableName)
{
//variable to return
DataTable lDataTable;
//variable to process
OleDbConnection lConn = new OleDbConnection(vConn);
OleDbCommand lComm = new OleDbCommand(vStrSQL, lConn);
OleDbDataAdapter lAdapter = new OleDbDataAdapter();
try
{
lConn.Open();
lAdapter.SelectCommand = lComm;
}
catch (Exception ex)
{
this.PWriteToEventLog(ex);
throw new Exception("Error from [PGetDataTable]\n" + ex.ToString());
}
try
{
lDataTable = new DataTable(vTableName);
lAdapter.Fill(lDataTable);
lConn.Close();
}
catch (Exception ex)
{
this.PWriteToEventLog(ex);
throw new Exception("Error ... \n" + ex.ToString());
}
return lDataTable;
}
When I run. It notice bug: Unhandle exception has your occured in your application.
Error... system.data.oledbexception: sysntax error in from Clause.
|
|
|
|
|
And yet, you posted all this crap, but not the for clause so we can tell you what's wrong with it ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
thuyphuongid wrote: public DataTable PGetDataTable(string vConn, string vStrSQL, string vTableName)
What madness is this ? Why do your methods and variables start with a letter ? What does P stand for ? Tell me v is not for 'variable' ???
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|