|
Before calling the Accept method, you must first call the Listen method to listen for and queue incoming connection requests.
Have you tried it
Whatever,still now if you receive a SocketException,you can use the SocketException.ErrorCode property to obtain the specific error code. After getting code you can refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.
I Hope it will work for you.
|
|
|
|
|
I didn't show all of my code.. sorry about that. I called the Listen for the WHILE statement. The problem is when doing it this way it blocks at the Accept() method. The way I have it works. I can accept connections and do what I want with the data (I'm sending / receiving serialized data). The problem is when someone goes and tries to stop the service.
That is when I try to call the Shutdown and Close method and thats when it hangs
I decided to use async sockets
modified on Saturday, November 6, 2010 12:48 PM
|
|
|
|
|
Just watching this VSTS 2008 Unit Testing 1 of 1 lets you know how to test methods that return something, my question here is how do you test methods in Visual Studio 2008 that don't return any value? For example:
private void BtnLoad_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select one or more media files";
dlg.Multiselect = IsEnabled;
dlg.Filter = "Media files(*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv)|*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv|All files(*.*)|*.*";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string[] files;
files = dlg.FileNames;
foreach (string file in files)
{
lstBxList.Items.Add(file);
}
}
}
|
|
|
|
|
You're trying to run an automated test on against a UI method. I may simply be a little old-school, but I typically don't write unit tests against UI methods because of the interaction required.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Your code is incorrectly written. This is a UI event handler and the code that you hav in it DOES return a value.
This dialog box code should be in its own method that returns a fully qualified path to the caller. It should NOT be sitting inside an event handler.
You also wouldn't run a unit test against a method that requires user interaction.
Another question. Why on earth would you use a nullable boolean to get the return value of a dialog box? It's either going to return true or false, never null. So, what's the point?
|
|
|
|
|
Right I see what your saying...First of all I should have pointed out that I am working with WPF hence use a nullable boolean to get the return value of a dialog box, the other way of calling a dialog box does not seem to work when developing a WPF based app. Secondly I used this as am example which I have to say after the response I got from fock was a bad example of which I was hoping fock would use it to illustrate how to test a method that does not return anything...Please bear in mind that I am a rooky,so if I say something that seems obvious to you, may not be the case with me...
|
|
|
|
|
Dave Kreskowiak wrote: Why on earth would you use a nullable boolean to get the return value of a dialog box? It's either going to return true or false, never null. So, what's the point?
Actually, it should return a DialogResult. The use of a bool condition would indicate that it's a WPF/SL dialog box, and this does return a nullable boolean condition.
|
|
|
|
|
I haven't done any WPF until very recently, and nothing on dialogs yet, so my ignorance is showing through there.
|
|
|
|
|
As defined that method can not be unit tested as it requires user input (to select the file). But as you want an example on how to test a method that doesn't return a value it can be refactored slightly as below.
To test a method that returns void you test for the change in system state that the method call is meant to impose. In this case the listbox should contain 2 items after the call, granted testing if items were added to a listbox is of dubious benefit but this is just for illustrative purposes.
private void BtnLoad_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select one or more media files";
dlg.Multiselect = IsEnabled;
dlg.Filter = "Media files(*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv)|*.mp3;*.wav;*.wma;*.avi;*.mp4;*.mpg;*.wmv|All files(*.*)|*.*";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
LoadFilesToListbox(dlg.FileNames);
}
}
public void LoadFilesToListbox(string[] files)
{
foreach (string file in files)
{
lstBxList.Items.Add(file);
}
}
[TestMethod]
public void TestLoadFilesToListbox()
{
LoadFilesToListbox(new string[] { "file1.txt", file2.dat" });
Assert.AreEqual(2, lstBxList.Items.Count);
}
|
|
|
|
|
I've got a COM object that has a memory leak. This normally wouldn't be an issue except that my program is a kiosk app so it's running continuously.
Using a different COM object is not an option. This is a standard visual COM object from a very large company. Rumor has it that the next version will fix the memory leak but the memory leak has been there for a long time so I'm not hopeful.
So my thought is to destroy the object after a certain amount of time so that the memory will be released and to recreate it. But I can't figure out how to destroy the object other than to close the window and reopen it.
Can anybody help?
Thanks.
Jeff.
|
|
|
|
|
Have a second, identical window behind it and then destroy it? It's a brute-force-and-ignorance approach, but it may work if you time it right.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Wrong forum, mate.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
See Marshal.ReleaseComObject[^] method, but if the memory leak is consequence of a defective programming of the COM object, maybe this will not solve the problem and, maybe, nobody will be able to solve it except for the company which developed it.
|
|
|
|
|
I told you what to do the last time[^] you asked this. For the benefit of others, the component you're talking about is Flash, and I suggested that you need to use AppDomains to cope with this.
|
|
|
|
|
Hi all,
I'm not a all day programmer, but C#/.Net is nice to get little administration processes.
But nothing is good without good coding style...
I will create a class which gives solutions to use if someone is calling this method.
I.e. like (ImpLink, Internetwork).
Sample Pic
In my method I will give a way to select different switches by choise with this options.
I know only this possiblity via "summary, and params" to give options for Intellisense
|
|
|
|
|
I'm afraid your question is not quite clear....
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
What is your question
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Maybe you want to know how to make an enum[^]?
|
|
|
|
|
yes I think I'm walking a step forward.
I was creating an enum and read out the integer.
But how can I transfer enum values to a method ?
At the moment i use "int MessageType"
I will call the Method Loggerschema
i.e:
LoggerScheme(ex.ToString(),MessageType.Error);
public enum MessageType1{Information=1,Error,Warning};
public void LoggerScheme(string ex, int MessageType)
{
if(MessageType==1)
{
// This is a Information Message
// But I prefer to give Type "Information" instead 1
}
if(MessageType==2)
{
// This is a Error Message
// But I prefer to give Type "Error" instead 2
}
if(MessageType==3)
{
// This is a Warning Message
// But I prefer to give Type "Warning" instead 2
}
}
modified on Friday, November 5, 2010 10:53 AM
|
|
|
|
|
Use the name of the enum type, instead of int:
public void LoggerScheme(string ex, MessageType1 MessageType)
Edit
And don't cast it to int, it is not necessary:
if (MessageType == MessageType1.Information)
...
|
|
|
|
|
Thanks a lot, that is the solution for all my problems
|
|
|
|
|
You're welcome. I wish all of my problems were like this one...
|
|
|
|
|
Erik's example above is a good way of making things typesafe.
|
|
|
|
|
Hi All,
I am new to .NET platform.
I have a C#.NET executable(.EXE) application. I would like to expose some interfaces for my client applications. What are the possible options for doing this?
Some of my ideas are..
1. Exposing interfaces via COM Interop
2. Using .NET remoting
Please help.
prvn
|
|
|
|
|
I think WCF[^] is better.
|
|
|
|