|
I am writing an app that needs to receive multicast data. However, the amount of data being sent on a single multicast group is enormous and I do not have any control over the publishing side of the data. So what I'd like to do is to run multiple instances of the same app on a single, high power machine and assign each instance of the app a manageable segment of the total multicast feed to process. So for example run 4 apps and let each of them process only 1/4 of the total amount of data each.
But here is the problem, which I hope one of you will be able to help me solve. If I run multiple instances that all try to join the same multicast group on the same machine I get the following error:
System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
This happens when the UdpClient object is being instantiated as follows:
udpClient = new UdpClient(portNumber);
The interesting thing is that I do not have this problem when I run an app that was built using Visual C++ and WinSock. It only happens with the .NET framework.
Does anyone have an answer to this other than "use 4 separate machines"?
Thanks
Robert
|
|
|
|
|
goodpilot wrote:
Does anyone have an answer to this other than "use 4 separate machines"?
Yes - don't use multiple processes. Multiple processes will not necessarily solve the problem and will most likely add to it. Each process has significant overhead: it's own process space, handles, thread queues, and in this case a separate instance of the CLR loaded. The common, "more correct" approach would be to use worker threads. You can either use the Thread class or the ThreadPool.QueueUserWorkItem (recommended; read about thread pools in the ThreadPool class documentation) to split the work. You could even make this configuration at launch time using the .config file for the application. This will use significantly less memory, cause the CPU to perform better in regard to your application (it's not switching to time-slice between multiple applications - on threads), and give you greater control...not to mention solve your problem (since one process is listening to the socket).
So, all data would be received by the UdpClient (it would anyway - you're just processing in chunks). Just chunk the data to one of N number of worker threads. This is actually how most socket servers work that you'll find any information about, and they can service hundreds or even thousands of connections.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
As usual you are a big help. I will looking thread pooling as a solution.
Thanks,
Robert
|
|
|
|
|
Hello,
I am working with the TraceSwitch class and am having a problem.
First I created a TraceSwitch variable:
static TraceSwitch traceSwitch = new TraceSwitch("FactorialTrace","Trace the factorial application");
Then, in my button click method I have code such as:
if(traceSwitch.TraceVerbose)<br />
Debug.WriteLine("Inside the button click event handler");
Then, I added an App.config file to my project and wrote this to its contents:
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<configuration><br />
<system.diagnostics><br />
<switches><br />
<add name="FactorialTrace" value="4"/><br />
</switches><br />
</system.diagnostics><br />
</configuration><br />
Now, when I try to debug the app I get this error at the first line I am checking the level of trace output
The following line:
if(traceSwitch.TraceVerbose)<br />
Debug.WriteLine("Inside the button click event handler");<br />
Gives this error:
An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: Unrecognized element
I cant find any errors in App.config or anywhere else. Does anyone have any suggestions?
Thanx for the help
-Flack
|
|
|
|
|
Does it say what element anywhere in the exception message? One thing to check is the file encoding, and use Edit->Advanced->View Whitespace and make sure there's no stray Unicode elements that would be invalid whitespace and may be treated as an element.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot for the quick reply!
I did as you suggested and discovered that one of the lines in App.config had a bunch of white spaces appended to the end of it.
I got rid of those spaces and everything works great.
Thanks for the help
-Flack
|
|
|
|
|
I have a C# installer class and I want to retrieve the ProductCode property within the code. How do I do that?
Thanks in advance.
|
|
|
|
|
I'm guess that you mean you added an assembly with an Installer class (attributed with the RunInstallerAttribute class) as a custom action within a Windows Installer package using VS.NET (or anything, really)?
If so, you have to pass it as a command-line parameter. In the Installer class, you can query command-line parameters easily using the Context.Parameters property. It's a simple dictionary. So, lets say you define a command-line parameter named "ProductCode", you'd access it like so:
public override void Install(IDictionary stateSaver)
{
string productCode = Context.Parameters["ProductCode"];
if (productCode != null)
{
}
} In the custom action command-line within the designer for the VS.NET distribution package (an MSI), add /ProductCode=[ProductCode] to the command-line. That will pass-in the ProductCode for the MSI as a command-line argument.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I am writing some business classes and want to use an enumeration for one of the properties. I am not sure about how to organize the code. I was going to put the enumeration into a separate file:
namespace MyNamespace
{
using System;
public enum EnumDayType : int
{
Weekend= 1,
Holiday = 2
}
}
Then in my class file:
namespace MyNamespace
{
using System;
public class DayType
{
private EnumDayType dayType;
}
}
Is this the correct way to organize my code across files? What are some of the naming conventions for the enumerations (should I preceed the name with Enum, for example)? Should I have a separate source file for each enumeration? Any other suggestions? Thank you.
|
|
|
|
|
It actually doesn't matter: there's no notion of source files when you compile (only in a PDB - programming database - which is used for debugging and is not typically generated for release builds).
Personally, I either define an enum in the class's source file that uses it if it's the only place where it's used, or have a file in my project just for enums used throughout the namespace for that project. You could use a separate source file, though; like I said, it really doesn't matter.
Use whatever organization makes sense to you, unless you're in a team environment; then the team must decide what works best for them.
The only real recommendations that the Visual Studio .NET and .NET Framework SDK docs assert is naming conventions. Read Design Guidelines for Class Library Developers[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i follow the article http://www.codeproject.com/csharp/tcpclientserver.asp
to obtain a client/server program and the code work well ... but thers's a tiny problem that the server accept the client then the client send the msg ; then what the client don't respond to any other messages from client
so what a peace of code i shoud modify so the server accept many messages as well in the current connection with out need to restart server .
thx in advanc..
ADEL K Khalil
|
|
|
|
|
If you have a question specific to a particular article, you should ask your question in the article's message board at the bottom of the article.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have written an application that runs on Windows Service. It runs fine (I overcame some of the problems I had with it earlier). It does perfectly everything that it is supposed to do - the only problem - after I start the service it runs for about a day or two and it halts (stops) by itself in the middle of the night. When I see it is stopped, I restart it and it gets back to its normal operation. I have to keep watching until it stops again. Is there known issue that can resolve this problem. Help would be highly appreciated. (vinayakkatkam@yahoo.com).
Vinayak Katkam
|
|
|
|
|
What problem? You didn't give a specific problem and we know nothing about your code so how can we diagnose it?
If you want to know what is happening with your service, you need to debug it. Since this problem takes a while to occur, the best way to debug it is to instrument it. The most basic way is to use the Trace facilities in System.Windows.Forms using the EventLogTraceListener . You can configure this progammatically or using the .config file for your Windows Service (which I recommend, since you can change it at runtime).
Throughout your code, use Trace.WriteLine to log state and events in a reasonable way so that when a problem occurs you can determine either what happened or in what part of your code the problem happened.
In your .config file (named the same as your application + .config and in the same directory, like MyServiceApp.exe.config), write something like this:
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="System.Diagnostics.EventLogTraceListener, System"
initializeData="Application" />
</listeners>
</trace>
</system.diagnostics>
</configuration> Then whenver you use Trace.Write or Trace.WriteLine (or even the corresponding methods on the Debug class, which is only compiled into your IL if the DEBUG symbol is defined by the compiler) the message will appear in the trace log (use eventvwr.exe to view it).
There are other, more complex (and better) ways of instrumenting your application but this is by far the easiest. It's a good place to start, especially since you gave us no specifics with which we can help you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In addition to Heath's useful suggestions, here is an alternative.
1. Write your code in a regular console/windows application, run and debug your code from the Visual Studio debugger (set break points at places where failures occur).
2. When it is "bug free", run it from XYNTService[^].
If you cannot figure out the bug but you have to deploy your app anyway, then you can use XYNTService to restart your app whenever it fails. Read the above article for details.
P.S. I understand this may not be a good solution under all circumstances.
My articles and software tools
|
|
|
|
|
Is there a means in which FolderBrowserDialog can select other computers that are browsed to? (Directories under remote computers can be selected but the machines themselves cannot). If not, is there some other class/mechanism that can accomplish this?
|
|
|
|
|
They can be, but you can't use the FolderBrowserDialog component in .NET 1.1 and newer. You must P/Invoke SHBrowserForFolder yourself and specify BIF_BROWSEFORCOMPUTER (0x1000) in the BROWSEINFO.ulFlags struct field.
There's no easy way to do this, however, since the FolderBrowserDialog doesn't expose any sort of Flags property. You might either search the CodeProject site (here, of course) for examples of someone who has or use a decompiler/disassembler like .NET Reflector[^] to see how the current FolderBrowserDialog works (it isn't easy, and require knowledge of P/Invoke and shell programming, though copying the code as-is may help).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I have a list of project files (all full path and name)
and I want to create a new solution and then add all these projects to this solution.
This is what I tried.
EnvDTE.Solution mysol = new EnvDTE.SolutionClass();
mySol.Create(@"C:\temp", "dummySolution.sln");
foreach(string myProj in _Projects) //_Projects is a list of project files)
{
mySol.AddFromFile(myProj, true);
}
mySol.Save(@"C:\temp\dummySolution.sln")
The application keeps on busy for a while and then I get a System.Runtime.InteropServices.COMEException
Additional information: Server execution failed.
Can anybody tell me what is wrong or what I should do instaid.
Thanks in advance,
Johan.
|
|
|
|
|
Hi,
I want to create a class and its methods at run-time. Users will write the class code in text-box and then use it.
How can I do this?
Savaş Külah
savaskulah@msn.com
|
|
|
|
|
|
I'm trying to create my own DLL as a part of interpreter. I'm having trouble to load the dll...
The DLL source code is (TestDLL.dll in system32 directory):
using System;
namespace StringDLL
{
public class DllStringTest
{
public string StringReturn(int value)
{
switch (value)
{
case 0: return "Zero";
case 1: return "One";
case 2: return "Two";
case 3: return "Three";
default: return "Unknown";
}
}
}
}
and in the main code I use to load the DLL is:
[DllImport("DllTest")] public static extern string StringReturn(int value);
then to call the function in the event handler:
MessageBox.Show(StringReturn(0));
I'm trying to return the string value from DLL library. I have been getting the error "unable to find the entry point in TestDLL dll."
I want to load dll only when needed. Can anyone help?
|
|
|
|
|
Hi,
The DllImport attribute is used when using functions exposed by non-.NET libraries. In order to use the assembly you're creating (TestDll.dll), you need to add a reference to it in Visual Studio .NET.
AFAIK, the assembly will not be loaded until you call anything located in it, so there's no no need to implement dynamic loading.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
DllImportAttribute is for calling native functions from native DLLs. Your code is managed code and the only entry point exposed is for the static Main method (by default, which is a compiler feature) of a .EXE assembly.
.NET assemblies you simply reference like you do System.dll, System.Windows.Forms.dll, etc.
In your project where you want to call StringReturn , right-click on your project and select Add Reference. If the project is in the same solution as your other project, click the Projects tab and double-click the project to add it. Otherwise, select or browse to the assembly that defines that method and add it to your project. Then use the fully-qualified class name (or add the namespace to your using statements toward the top of your source file) and call the method. Since it's an instance method, you'll need to instantiate DllStringText .
If you're trying to call arbitrary methods in any assembly dropped into your process's current working directory, you'll need to implement more of a plug-in style application, which usually uses an interface or abstract class to provide abstract access to an implementation and a way to find that implementation. Searching through an assembly is far too expensive to find such types (though possible), so one usually uses a .config file and custom IConfigurationSectionHandler implementation to register types (this is used for the provider pattern-style of programming).
Try the following search for several good plug-in articles:
http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=plug-ins[^]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To clarify this... I would need to have the dll be explicively load the dll. I would like to avoid using the "Add Resource" in the .net editor.
|
|
|
|