|
Thanks
This is not helping, after checking , canRead is true, but then when calling readstring it hangs, even that I sent data from the other side...
If not checking, when sending data from the other side (client) it reads ok.
only when there is no data, and I am trying to read, its hangs...
Maybe that is a clue why its hang when calling ReadString()?
|
|
|
|
|
No quite sure I understand exactly what you mean here, but the chances are the BinaryReader is blocking (eg. waiting for data to arrive) which is causing your hang. This makes sense, you can't read what hasn't been sent yet.
When sending data over a network stream, some buffering is employed too. So writing a single byte to the stream doesn't mean it will be transmitted. The .NET framework will wait until a certain amount of data is present in the stream before sending it. You can't send single byte network packets out. If you think that might be the problem take a look at flushing the underlying stream. This causes all the data in the buffer to be sent immediately.
Also, on something like this, you want to use multithreading. In particular the server will have multiple client connections, each needs to be served by its own thread. It's usual to send the TcpClient which is returned from AcceptTcpClient() to its own thread until the connection is closed. Without that, your server can only accept one connection at a time - surely not that good for a chat application.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks Rob
I guess you right, the binaryReader is blocking, but I don't understand why... its suppose to return null if there is no string to read.
When there is a string that I sent from the client, he reads it and everything is ok, so I don't understand whats going on.
As I checked, I don't need to flush, cause sending using binary writer on the client is ok and I am getting it ok at the server.
I am using BackgroundWorker to call Chat.ReadLine(), and off course this is only a sample that I am doing to learn a bit, it will not be a real chat application, only academic reasons.
(not less important )
Thanks,
Ady.
|
|
|
|
|
You're welcome!
I'm surprised that BinaryReader is supposed to return null if there is nothing to read. I can't find anything to support that assertion on the net (just a quick look). Particularly, if I call something like ReadInt32() on it, there's no option for returning null as its a value type.
Also, you can attach it to any type of stream behind the scenes, so it's more the behaviour of the backing stream than the reader itself.
Regards,
Rob Philpott.
|
|
|
|
|
Yes, my mistake. I assume that if string is not availe, then it will return null.
The solution was to check the stream and not the reader:
if (ns.DataAvailable) return binaryReader.ReadString();
Thanks
Ady.
|
|
|
|
|
Hello everyone,
In my scenario there are resources (e.g Hashtable, String, Collections...).
The resources are:
1. By definition ReadOnly
2. Loaded on-demand from the file system / DB.
3. Big memory consumer.
4. Thread Safe
5. Read by different Threads. (So it's called Shared Resources)
The question:
Because the resources are big memory consumer, I'm looking for idea how to get those goals and make sure to release the resources when I don't need them.
The problem:
If the resources hold by global objects (Global objects so different threads will be able to read them) - The Resources will never get be freed by the GC because the global objects will be static or will be hold by the client until termination.
Any idea ?
Thanks
|
|
|
|
|
Sort of defeats the purpose of having a global object it seems to me. I use these to reduce the reads to the Db for static classes/tables and regularly set them to null, I assume this reduces the memory footprint for the object (that's not why I do it but I would assume that would be a consequence).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Moshe T wrote: The Resources will never get be freed by the GC because the global objects will be static
Read about WeakReference[^] class. MSDN has got an example which will help you to get started. Quoting from MSDN,
A weak reference allows the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can still obtain a strong reference to it and prevent it from being collected
Other idea is to have a separate thread which looks in the collections frequently and removes the items from it which you don't require.
Edit
You can also create a new application domain for your threads and collections. So when you don't need it, just terminate the application domain and all your resources will get released.
|
|
|
|
|
Is it possible to add a Linecap to a GraphicsPath? I've played around a bit and it looks like I'm going to have to change my paths to lines, but I'm a novice so if anyone has a genius workaround it would be much appreciated!
Thanks in advance
|
|
|
|
|
Hi,
I haven't done this but I expect all Graphics.DrawXXX() to obey the Pen properties, so I suggest you set StartCap, EndCap (and sufficient Width) to enjoy line caps.
|
|
|
|
|
Just in case you are still having problems, take a look at the application from this[^] link. The app has an option to turn linecaps on/off for the GraphicsPath .
I tried to post this last night, but the servers were misbehaving so I gave up and went to bed.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks.
The problem was that the path did not originally have caps, and so CloseFigure() was used to end the path. Removing this allowed Linecaps to be added, and the Caps automatically close the path anyway.
|
|
|
|
|
VS 2005
C#
Crystal Reports
I created a gridview that returns the contents of the the 'reports' directory in my web project. It displays the *.rpt files as links. The links point to an aspx page that contains a <CR:CrystalReportViewer ID="crystalReportViewer" runat="server" />. I am trying to dynamically pass in the reportPath by doing something like this: (report path will change depending on the link that is clicked on)
string reportPath = Server.MapPath("Reports" + Eval("name"));' but when I do this I get an error that states:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. I am new to this and was wondering if somebody could give me an idea as to how I could get the report the corresponds to the link that I click on.
|
|
|
|
|
Try this:
string reportPath=Request.PhysicalApplicationPath + "Reports\\" + name );
where name is the .rpt filename.
|
|
|
|
|
Hi thanks for the response.
I tried what you recommended and it did not work. The 'name' is the file name which is in a directory called reports, I get the name from the code below. When I try to pass the name to the Report path it tells me I can do that.
DirectoryInfo di = new DirectoryInfo("C:/Inetpub/wwwroot/ITS_USA/Reports");
FileInfo[] rgFiles = di.GetFiles("*.rpt");
gvReportList.DataSource = rgFiles;
gvReportList.DataBind();
foreach (FileInfo fi in di.GetFiles("*.rpt"))
|
|
|
|
|
Do you receive any error ?
I think the code you use to full the grid is fine.
|
|
|
|
|
Yes, The name 'name' does not exist in the current context.
|
|
|
|
|
Ok I got it,
in this part:
string reportPath=Request.PhysicalApplicationPath + "Reports\\" + name );
You have to replace that with the variable where you have the .rpt file name, I suppose one value from the grid...
Si the result should be something like:
C:\Inetput\wwwroot\myapp\reports\report1.rpt
Where Report1.rpt is the value from your variable.
|
|
|
|
|
Yes that is what I am trying to do.
the variable name comes form the directory info. class. I then want to pass the 'name' of the file precededed by the folder 'reports'. So just like you mentioned it would dynamically create the report path. Hmph. Nothing is ever easy when your new.
modified on Tuesday, April 21, 2009 12:37 PM
|
|
|
|
|
Hello,
Does anybody know how to return $? and $LASTEXITCODE back to the C# caller after a script has been executed using Jean-Paul Mikkers async powershell code execution from c# article here on code project with the address below.
Asynchronously Execute PowerShell Scripts from C#[^]
regards
Bob.
|
|
|
|
|
Dear sir,
i want to control system sound using wpf slider control.
how can i do?? any idea??
yogesh
|
|
|
|
|
did you even try and google that, if you don't know how more info can be found here[^]
this might help either
clickety[^]
|
|
|
|
|
Dear sir,
i have searched in google but i didn't get anything . that is why i posted here.
yogesh
|
|
|
|
|
|
buachaill cliste wrote: did you even try and google that, if you don't know how more info can be found here[^]
Awesome. That's the best thing since www.lmgtfy.com[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|