|
First to clear up some confusion.
TCP, upon which netTcp is built has the following behavior.
The only almost sure way to tell if the other end is still there is to send something to it. And then wait for a timeout/failure. And even that might not tell you (but probably will.)
In a normal situation such a failure would occur quickly because the other end closed the connection.
In abnormal situations the connection can be lost without a close. One way is to kick the power cord out of the wall.
This is how TCP works. And there is no magical way to get around it.
Some possible solutions.
1. The server closes the connection if it hasn't received anything for X seconds. The client must send soemthing, even a 'do nothing' every X/2 seconds to insure the connection remains alive.
2. Don't attempt to keep connections open. Open it, send, close. Do NOT be swayed by 'performance' issues around this. Those issues are related to high volume servers in data centers.
teknolog123 wrote: if server's response time exceeds 10 secs
You need to DESIGN for failures. As an example what happens if the server gets bounced right then? Normal maintainance (or maybe not so normal) but not a catasphrophic failure but it isn't going to respond. So exactly what does that mean to your application. Maybe you could queue the 'ok' and if so then you should queue it right away regardless and then send it on a different thread.
|
|
|
|
|
jschell wrote: You need to DESIGN for failures
Or design to avoid failure situations. By trying to use some sort of pesistent connection you add the possibility of a connection failure.
|
|
|
|
|
PIEBALDconsult wrote: Or design to avoid failure situations.
One can certainly ignore failure scenarios. But other than that it isn't possible to create a multi-server dependent system and not have failure situations.
PIEBALDconsult wrote: By trying to use some sort of pesistent connection you add the
possibility of a connection failure.
Yes but...
For connectivity within a data center that is low.
For high volume within a data center connectivity might make a performance difference.
Failure scenarios due to lost connectivity exist even with non-persistent connections.
|
|
|
|
|
jschell wrote: This is how TCP works. And there is no magical way to get around it.
you really cleared the confusion with this info. Thanks
|
|
|
|
|
Hi
i am new to the world of .Net, i want sample code and some information about online exam. please help me any one. My requirements are
1.Admin provides the hall tickets for users.
2.user can login with hall ticket number.
3.countdown is starts when user starts the exam.
4.user has to answer for ten question within a time otherwise the page will be closed.
please help me anyone. my mailid is swati.balina@gmail.com
swathi
|
|
|
|
|
Try something and then post issues you run into here (with code samples).
Someone will surely help you out.
|
|
|
|
|
See the whole point of a training course is to show that you are qualified in the subject in question. If you just copy answers, you're going to end up as one of those 'certified experts' that ends up on The Daily WTF because you don't actually know what you're supposed to.
|
|
|
|
|
Nice requirements.
Unfortunately, we are not a coding self-service, some kind of machine where your put your requirements and which gives you instant solutions.
If you are new to .NET, I suggest you study the language first, along with the use of the IDE.
It will give you some clues about how you are going to deal with these requirements.
Then come back here when you have specific questions.
I would finish saying 'Never put your email address on a forum', but if you really want to be spammed, it's your choice.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
Hi all,
In my c# application by using one predefined function i am getting the whole xml file in a string.
And i am having one class file which is used for serialization.
But now the problem is the string in which i am getting whole xml file from that i want to read the value of a node and assign it to one of the member of the class file.
How can i do it ?
Thanks in advance.
|
|
|
|
|
You can use XElement to read nodes within an xml file.
Here[^] is a nice and easy example on how you could do this.
|
|
|
|
|
Countered the 1 vote on this since it seems to be a good answer.
|
|
|
|
|
|
You can use LINQ to XML which is probably the easiest and most performant way of doing it. (And it is this way that uses the XElement class mentioned earlier.
They're are good tutorials on LINQ here at CP or on google.
V.
|
|
|
|
|
-I am trying to learn how to load up a Gallery of images to asp website.I understand I could load thumbnail images to reduce original size. Here is some code I tried after googling, but its still loading original size.
-Also, Can I make these images look more alive, like clikable, or double their size whenclicked?
protected void btnsave_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(fileupload1.PostedFile.FileName);
string targetPath = Server.MapPath("Images/" + filename);
Stream strm = fileupload1.PostedFile.InputStream;
var targetFile = targetPath;
GenerateThumbnails(0.5, strm, targetFile);
BindDataList();
}
private void GenerateThumbnails(double scaleFactor, Stream sourcePath,string targetPath)
{
using (var image = System.Drawing.Image.FromStream(sourcePath))
{
var newWidth = (int)(image.Width * scaleFactor);
var newHeight = (int)(image.Height * scaleFactor);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}
}
protected void BindDataList()
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/Images"));
FileInfo[] files = dir.GetFiles();
ArrayList listItems = new ArrayList();
foreach (FileInfo info in files)
{
listItems.Add(info);
}
dtlist.DataSource = listItems;
dtlist.DataBind();
}
modified 30-Oct-11 23:34pm.
|
|
|
|
|
|
For generating thumbnails, take a look at the GetThumbnailImage method of the Image class. It's perfect for this — I've used it for just this purpose in the past (displaying small images to save bandwidth and load time on an ASP.NET site).
I can't help you with displaying them though, as you don't show any markup or your Page_Load method and the like.
Remember, though, that if you are generating thumbnails on the fly in memory on the server, these do not exist anywhere on disk. When the HTML is loaded in the client browser, the img element needs an src URL. This is, as you probably know, typically a direct link to a .jpg somewhere on your webserver virtual directory or something. Usually it is a disk file. Since these are not really saved, you can't link to a file. But you have to link to something!
What we did is create an aspx page that returns image data (not html). You can find a good guide to this here (which also shows using the GetThumbnailImage method I mentioned before). You then will basically use an Image control and set its ImageUrl to MakeThumbnail.aspx?file=picture.jpg or the like. In our case, we had images stored in a database, so we used an integer id instead of a file name.
|
|
|
|
|
Check out ... here on CP : "LeftImage - An Image Optimization Library with Fluent Interface"[^].
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
Another route to consider is to use the newer features of CSS Image transformations (which I have not tried myself)?
A recent SitePoint article; although its focus is on background-image transformation, the article implies a broader usage: "Scaling, skewing and rotating any element is possible with the CSS3 transform property. It’s supported in all modern browsers (with vendor prefixes) and degrades gracefully."[^]
good luck, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
hi, I'm using the below code to close some programs.But it seems like it's not the best practice. would you recommend me anything better? Thanks.
Process[] runningProcesses;
Queue programsToBeClosed;
public void closePrograms(Queue programsToBeClosed)
{
foreach (string program in programsToBeClosed)
{
foreach (Process item in runningProcesses)
{
try
{
if (item.ProcessName == program || item.MainWindowTitle == program)
{
item.Kill();
}
}
catch (Exception)
{
}
}
}
}
|
|
|
|
|
You declare your variables runningProcesses and programsToBeClosed but you never initialize them.
So they will be null in your foreach loops.
Moreover, are you sure a Queue is a list of strings ? Did you try to debug your piece of code to see what's going on exactly ?
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
my variables are already initialized and code is already working and doing its job, I just wanted to ask whether it's good practice.Because nested foreach seemed to much code to me. Thanks
|
|
|
|
|
I would avoid the use of one of the foreach loops. This way :
Process[] runningProcesses;
List<string> programsToBeClosed;
public void closePrograms(List<string> programsToBeClosed)
{
foreach (Process item in runningProcesses)
{
if ((programsToBeClosed.Contains(item.ProcessName)) || (programsToBeClosed.Contains(item.MainWindowTitle)))
{
try
{
item.Kill();
}
catch (Exception)
{
}
}
}
}
Hope this helps.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
this is it! Thank you very much for your help
|
|
|
|
|
This might actually be worse as Contains probably iterates over the collection and you're calling it twice.
|
|
|
|
|
This might, even if I didn't test it. Thanks for pointing it out.
Maybe using two HashSet<string> would help ; first, lookups for hash should be quicker ; second, it could be taken profit of Union() and Intersect() methods to build a list of process names to be closed.
But it's just a guess ; and I won't have time to measure gains or losses. Maybe the OP will.
No memory stick has been harmed during establishment of this signature.
|
|
|
|