|
I always keep track of the connected client sockets, so that I can disconnect them at will, for example to restart the server in a correct manner. If you keep track of the connected client sockets, you can simple get the size of the list which gives you the number of connected clients.
WM.
What about weapons of mass-construction?
|
|
|
|
|
hi
i found an article in codeproject as DataGridPrinter that print datagrid good. but it has written with VB.Net and i want it in csharp. when i create dll in VB.Net and i use it in c# the following error shown me :
Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'
and when i set Datagrid1.DataSource = ds1.Tables["Table1"]; the following error shown me :
//in Line 374
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
how to solve my problem and do you have a other class that print datagrid in C# with header and footer ?
thanks ..
|
|
|
|
|
There is a forum provided under the article, that's the place to go to get help on the article.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
How to play a sound from my program.
I have Visual Studio 2003.
Net 1.0.]
Help.
Vasildb
|
|
|
|
|
using System.Runtime.InteropServices;
[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern int Beep(int dqFreq, int dqDuration);
Beep (3000,25);
=> It will play a nice beep like in '80 years
If you are not happy with that you can also use the MCI functionalities provoded by the API (need import also)
or ... simply play wave with:
[System.Runtime.InteropServices.DllImport("Winmm.dll")]
private static extern bool PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
La Richesse & la Gloire ne griseront jamais que les temples
|
|
|
|
|
hi ,
i writing a application in that i want to read or send data to one port(COM2)
i using C#.net2003 thatwhy i can't use
namespace SerialPort
i must use win32 API
plz give a sample program for sending the data to COM2 port in C#.net
it's very usefull in my application plz
Thanks
|
|
|
|
|
Could someone point out why there is an error here?
Thanks.
class BankAccount<br />
{<br />
<br />
decimal m_ID;<br />
<br />
public BankAccount(string ID)<br />
{<br />
m_ID = 0;<br />
}<br />
<br />
}<br />
class SavingsAccount : BankAccount<br />
{<br />
decimal m_ID;<br />
<br />
public SavingsAccount(string ID)<br />
{<br />
m_ID = 0;<br />
}<br />
}
|
|
|
|
|
Since the SavingsAccount ctor doesn't have an explicit call to the base class ctor, the compiler will insert a call to the default ctor (the one with no parameters). But there is no such ctor, so you get the error. You need to add the call to the initializer list:
public SavingsAccount(string ID) : base(ID) { ... }
|
|
|
|
|
|
How can I display drgged object's shadow (or faded image) with the mouse pointer? Thanks.
|
|
|
|
|
You can change the cursor if you have a static image you want to show under the mouse. Otherwise, you need to draw it yourself.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If i make a stream of some sort out of it, and write to the stream, will the online file be edited?
I don't suspect so. Is there something i can do to do this?
|
|
|
|
|
Sure - if you have FTP write access, you can read the file, change it, and write it back.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Excellent, im so happy... well y'know.
|
|
|
|
|
when i'm looking at a value and using console.writeline(byte[0]); to print the output of a network stream. i am getting a 69 printed to the screen. is this an octal number or the binary number 69? 01000101?
|
|
|
|
|
It is 69 in decimal (01000101 binary). I don't know how/if C# can display octal.
A byte array is just a bunch of bytes - numbers that can range between 0-255 decimal, 00000000 to 11111111 binary, or 000-377 octal.
HTH,
Mike
|
|
|
|
|
If it was octal, it wouldn't have a 9 in it. If it was binary, then it wouldn't have a 6 OR a 9 in it.
I would have thought byte was a keyword and couldn't be an array name...
If you're worried, use ToString and pass it a format so you know what it is.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi All,
I have a product which I am planning on distributing to a few Beta testers. I thought it would be a good idea to incorporate some sort of licensing/registration scheme for it, so I can control it, have a trial version that expires after a certain period of time, etc. Does anyone have any experience with licensing solutions that can be used with .NET components?
Thanks,
Aaron
|
|
|
|
|
I'm trying to get a delegate to a property. Tip 2, solution 2 of the article linked below gives a way to do it. It works but a typo in the propertyName wouldn't be detected until runtime.
http://www.codeproject.com/csharp/csharptips.asp
<br />
private MySetDelegate xSetter = (MySetDelegate)Delegate.CreateDelegate(<br />
typeof(MySetDelegate), targetObject, "set_X");
I'm looking to replace the "set_X" parameter with the equivilant of "set_" + GetPropertyName(targetObject.X) , but having never used reflection before I don't know how to implement GetPropertyName or the equivilant.
|
|
|
|
|
Maybe I misunderstood the question, but you already have the property name (targetObject.X). Why do you need it again?
BTW, you can also achieve the same effect by creating a delegate to PropertyInfo.SetValue[^]. The code would then look like
class Test
{
int x;
public int X
{
get {return x;}
set {x = value; }
}
}
delegate void XDelegate(object obj, object value, object[]index);
static void Main(string[] args)
{
Test t = new Test();
PropertyInfo propertyInfo = t.GetType().GetProperty("X");
XDelegate xdel = new XDelegate(propertyInfo.SetValue);
xdel(t, 2, null);
Console.WriteLine(t.X);
}
|
|
|
|
|
S. Senthil Kumar wrote: Maybe I misunderstood the question, but you already have the property name (targetObject.X). Why do you need it again?
The issue with entering it into the code as a string is that typos aren't detected until runtime. This has burned me severa; times already.
Thanks for the delegate example. The only one I was able to find left the impression that it only would work with classes that supported the Invoke method, which mine did not.
|
|
|
|
|
dan neely wrote: The issue with entering it into the code as a string is that typos aren't detected until runtime.
A very valid concern, but that's the cost of using reflection and runtime method invocation, I guess. You have to make assumptions that cannot be verified at compile time. Instead of hardcoding a string, you could, for example, get all properties on a class and access the nth property, but that assumes new properties are always added at the end.
|
|
|
|
|
.NET newbie question
I have a Collection object that I would like to copy into another collection object.
The collection is of type:
System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule>
The Collection.CopyTo method requires that I provide an array and an index. The question is: How do I syntactically express the array portion of the target collection.
I can't do this, because param 1 is a Collection:
Collection1.CopyTo(Collection2, 0)
I hoped I could do something like this to specify the array, but alas no:
Collection1.CopyTo(Collection2[], 0)
Is there a way I can do this or do I have to enumerate the contents of Collection1 and Add to Collection2?
Thanks
|
|
|
|
|
Well, you could always do
Collection2.Clear();
Collection2.AddRange(Collection1);
|
|
|
|
|
No such method (AddRange) on the Collection class.
|
|
|
|