|
socket.Receive works with a blocking socket, that means, it blocks the thread until readable data is available. Your loop is correct.
Do you have any calls to Application.DoEvents or Thread.Sleep ? These methods reduce CPU usage, so that other processes can run, even though your program is receivingg bytes.
public void listensend()
{
while(keepalive)
{
byte[] buffer = new byte[1024];
int rcount = sourceSocket.Receive(buffer,buffer.Length,0) ;
Thread.Sleep(100); //hey, you're not the only process on this machine!
...
_________________________________
Vote '1' if you're too lazy for a discussion
|
|
|
|
|
Application.DoEvents???
Hmm... what I'm doing for the server is accept messages from clients. So the buffer in the code will be changed into a string, and then I will parse the string to know what kind of message did the client sent.
Based on the message I will do necessary functions like looking for another client, or getting necessary information, and then the final action would be this server will send string messages.
so in the code I have a series of if statements
if(command == ....)
{
...
...
clientSocket.Send()
}
if(command == ....)
{
...
...
clientSocket.Send()
}
I will try the Thread.Sleep now..
|
|
|
|
|
I have tried the thread.sleep and it does tone down the cpu usage.
I was just wondering whether using sleep can lead to a lesser performance, like when the client is expecting faster continuous replies from the server.
I imagined the thread will sleep on its every run, so it cannot give continuous messages.
Is there any other way around this issue?
|
|
|
|
|
i need to read a .txt and .doc file, then get few random sentences from it, anyone know how can i do that ?? i'm really headache about it ~ ~
|
|
|
|
|
Sentences start typically with a space and end with a period, or a couple other punctuations...So tear it apart using a StringBuilder, then use a Random number seed to go through the StringBuilder array of sentences..and wallah!! Should not be to hard...
"Your KungFu is not strong enough"
|
|
|
|
|
This may sound simple yet I keep running into this problem and re-implementing solutions, heres the deal, this example is over simplified for discussion reasons...
Lets say you design a program with a Listview (or some other non databound control), each item in the control can have up to 1-10 different functions, lets say 400 items in the control. So each item can only have one function but have the possability of up to 10 different ones.
Ok so you need a way to manage this data in the background while the user works with the list in interface, Arrays? Hashtables? Collections? DataSets? Well my current pick of the litter is a DataTable, I use two columns one for "Items" and one for "Function" then whenever the user changes the list I clear it completely and reiterate through the DataTable using a for each and repopulate it. This seems very very clunky and sloppy, not only do I have to do something like Class.Add(listview,item,function) or I set the listview item earlier on during loadup to a ListView declaration inside my class and I manipulate it from my class, I have never been a big fan of handing off controls to a class and letting the class manipulate the control through reference...Just doesnt seem very clean...
Does anyone have any thoughts on this?
Thanks, Eric
|
|
|
|
|
Hello,
I'm trying to find all of the concrete classes in an assembly that derive from an abstract base class that I've defined. I'm using the following code to create a StringCollection of the class names. The collection being returned has no items inside of it when I pass it the current assembly and the my custom type. However, I can pass it another assembly along with another abstract type (such as CollectionBase) and it returns the correct number of items. Does anyone see anything obvious that I screwed up? I believe I've been looking at this code too long to be able to spot an error.
Thanks,
Will
public static StringCollection GetConcreteDerivedClassList(System.Reflection.Assembly asm,
Type typ)
{
StringCollection ret = new StringCollection();
foreach(Type t in asm.GetTypes())
{
if(QAUtility.ClassIsConcreteDerivative(typ, t))
{
ret.Add(t.Name);
}
}
return ret;
}
public static bool ClassIsConcreteDerivative(Type tBase, Type tDerived)
{
bool ret = false;
if(tDerived.IsSubclassOf(tBase) & !tDerived.IsAbstract)
{
ret = true;
}
return ret;
}
|
|
|
|
|
Are your classes in the passed assembly public?
Regards
Senthil
|
|
|
|
|
They are all public. Even so, shouldn't Assembly.GetTypes() return all types in the assembly?
Will
|
|
|
|
|
Correction, Assembly.GetTypes() returns all the types in the assembly, PROVIDED that you pass the assembly you actually meant to pass. I, however, did not. I think I should probably get some sleep before I try any more coding. The four hours a night for the last three nights was apparently insufficient.
Thanks for the help.
Will
|
|
|
|
|
How could I fill a Ellipse with one color, making the center most intensive, and the intensity fades as the distance from the center increase.
I tried to use LinearGradientBrush, but could not find a mode for ellipse.
|
|
|
|
|
Hello fellow programming, what you are seeking comes with good fortune and happy tidings..LOL!!!
You want whats caleld a PathGradientBrush which is derived from GraphicsPen...Lemme type up some code for you, I will not have tested this but you will get the idea...
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics
GraphicPath gp = new GraphicPath();
gp.AddLine(10,10,110,15);
gp.AddLine(110,15,100,96);
gp.AddLine(100,96,15,110);
gp.CloseFigure(); //its a box duh!!
g.FillRectangle(Brushes.White, this.ClientRectangle); //paint the form white...
g.SmoothingMode = SmoothingMode.AntiAlias; //otherwise it looks like crapola
PathGradientBrush pgb = new PathGradientBrush(gp);
pgb.CenterColor = Color.White; //the middle "cone"
pgb.SurroundColors = new Color[]{Color.Blue,Color.Red}; //Surround Colors, pass in an array of colors...
g.FillPath(pgb, gp);
g.DrawPath(Pens.Black, gp); //draw the stupid square...its not perfectly square prolly
pgb.Dispose();
gp.Dispose();
}
|
|
|
|
|
|
The error is: 'Class1.frmAccount.txtOwnerName' is inaccessible due to its protection level.
<br />
public void ShowAddAccount(string Name)<br />
{<br />
frmAccount frmA = new Class1.frmAccount();<br />
frmA.txtOwnerName.text = Name;
frmA.ShowDialog();<br />
}<br />
When I change "private System.Windows.Forms.TextBox txtOwnerName;" to public in frmAccount then it says "'System.Windows.Forms.Control.text' is inaccessible due to its protection level"
I know this is a logical mistake but I still need help. Thanks in advance.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
text with lower case is an internal property. Try Text. Then make it a property.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Ooops.. Trouble for VB programmers huh?
Thanks Christian
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
hi there,
I have a Solution with two projects. Both projects have a main method to open its own.
- projectA - formA(with a main() method) - buttonA
Solution
- projectB - formB(with a main() method) - buttonB
I want to open formB in projectB by clicking buttonA.
private void buttonA_click(){
projectB.formB fb = new projectB.formB();
fb.Show(); // open projectB
this.Visible = false; // close projectA
this.Dispose();
}
But," this.Visible = false; and this.Dispose();" statements cause both projects closed.
1) how can Open a Project, then close another one by not using " this.Visible = false; and this.Dispose();" ??
Thansks
|
|
|
|
|
luckyShek wrote:
this.Visible = false; // close projectA
This hides child windows as well, such as the one you created.
luckyShek wrote:
this.Dispose();
Oh, someone shoot me. projectB exists as an instance inside projectA. What did you expect this would do ?
You probably want to use ShellExecute to just run the other program, then close this one.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
hi there,
I had created a UserControl.exe. I want to add it to a project by using "Add References". But it only take .dll file.
1) Can I just rename UserControl.exe to UserControl.dll ? 2) Will it cause any error ??
3) What's the best to create a userControl file with .dll in vs.net ?
Thank you very much.
|
|
|
|
|
luckyShek wrote:
What's the best to create a userControl file with .dll in vs.net ?
Set the compiler to build a dll.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
|
|
An EXE and a DLL contain different headers. An EXE contains an entry point while a DLL does not, though it typically contains a load address of where in memory relative to the EXE base it should be loaded. In the case of .NET assemblies, the EXE entry point references mscoree.dll!_CorExeMain , which creates the unmanaged AppDomain, loads a managed AppDomain then your assembly, and runs the entry point. A DLL will simply load into the process space but contains no entry point. While the IL module(s) contained in the assembly are basically file format-agnostic, the PE/COFF headers of the executable that contain the manifest and IL module(s) (and any other embedded files or resources) are different.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
In C#, during compile time, if you try to assign a int to a short, you will get a compile error.
In runtime, I need to check if a certain type can be assignable to another without loss of data.
(ie. it is fine to assign a short to an int, but not the another way around.)
System.Type has a function isAssignableFrom.
Unfortunately it only returns "true" if the types are the same. Are there any ways I can do assignability checking?
Thanks!
|
|
|
|
|
You could use reflection and the MaxValue/MinValue properties on types to write a method that does this for you.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|