|
I don't think you need the charArray. I'd write it:
StringBuilder output = new StringBuilder(length);
for ( int i = 0; i < length; ++i )
{
output.Append( sr1.Chars[i] );
}
return output; Untested, YMMV, etc.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
hi!
I need to read the sql messages returned from a incode "ScriptDiagram2.ExecuteNonQuery();" call without changing the script returning this messages.
a pic explaining what i mean:
http://shrani.si/f/2X/12w/3xylbIqA/untitled.jpg[^]
is this possible? how could i read this.
Thanks for any help!
|
|
|
|
|
This isn't specific to C#, but anyway: write an event handler for the InfoMessage event of the connection (see the docs for details). It will fire for PRINT statements and errors with a severity of 10 or lower. Also see the documentation of the FireInfoMessageEventOnUserErrors property - it alters the behaviour of the InfoMessage event.
An example of what you want to do is here: http://devio.wordpress.com/2008/05/15/displaying-printed-sql-output-in-aspnet/[^] (Google for "sqlcommand print" - no quotes - and there are other examples as well).
Later,
--
Peter
|
|
|
|
|
hi
i am writing a new UerControl (inherites from MaskTextBox), and i want to override some events like OnKeyDown, like this :
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
if (this.SelectionStart < 4)
{
string text = this.Text;
this.strYear = text.Substring(0, 4);
int num = int.Parse(this.strYear) + 1;
this.strYear = num.ToString();
this.strDate = string.Format("{0}/{1}/{2}", this.strYear, this.strMonth, this.strDay);
this.Text = this.strDate;
e.Handled = false;
}
}
base.OnKeyDown(e);
}
as u can see, when user press Up button, the year increament 1 unit, it works correctly, but i want to cancel event to prevent change focus character, while the focus character changed when user press Up button, i'm also use e.Handled = false; to prevent this, but it's not affects, how to solved my problem ?
thanks
|
|
|
|
|
If you want to cancel the key press you need to set Handled property to true.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
thanks Giorgi
but when i comment this code, your suggestion works correctly :
if (this.SelectionStart < 4)
{
e.Handled = true;
}
otherWise doesn't works correctly.
please test my code.
thanks
|
|
|
|
|
I am using IFilter got the property id and property value of docx file but can't get the property name.
But I am unable to get the property name. So please help me.
|
|
|
|
|
I have to chop up some seriously large TIFF files into small tiles in png format.
The source files are approxx 8000x8000 pixels, and the output tiles will be about 100x100 pixels.
I've written code to do this with GDI+ :- open the source image, and loop through creating target images, and getting Graphics.FromImage etc to draw them.
but it's very very very slow. I've tried multithreading to use my multiple cores, but the threads don't seem to schedule simultaneously - seems that something in GDI+ is stopping that working.
Anyone know of any suitable image processing componenets that can do this task more effiecently?
Thanks
Jon
|
|
|
|
|
Have you tried scanning through your source image using an unsafe region?
public static bool Extract(Bitmap b)
{
BitmapData bmData = b.LockBits(new Rectangle(0,0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
IntPtr scan0 = bmData.Scan0;
unsafe
{
byte *p = (byte*)(void*)scan0;
}
} The code you are using to extract your image portions would obviously go after the byte* p section.
|
|
|
|
|
I created one custom control and would like to use this control in other application. Usually by using dll of custom control in application we can use that control.
But I used _paint event in my class to create the control, which is not possible to create the same in class library project.
Is there any other way to include the custom control dll in my application. Thanks in advance.
|
|
|
|
|
Krish Agn wrote: But I used _paint event in my class to create the control, which is not possible to create the same in class library project.
What makes you think this ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
My custom control is: One Textbox control is merged in a cirle, So the shape of textbox looks round instead of square/rectangle.
Is there anyway to use textbox control in classLibrary project?
|
|
|
|
|
Try importing the System.Windows.Forms DLL?
Will make your class library ALOT bigger, yet it will work
I had the same issue whilst attempting to create custom Paint events in my DLL
-= Reelix =-
|
|
|
|
|
Say i have a server running and several client connected to this server. How to program
1)to detect when a client on purpose power down his PC without closing the connection
2)the client's pc hang causing connection to server be disconnected
Thanks in advance
|
|
|
|
|
One possible way is to keep some table to track the last activity time of each client. If it is more than some acceptable window we could assume there is something went wrong with the client.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
what will be the best timing to consider a connection has broken
|
|
|
|
|
It is a matter of what your application does...You will have to figure it out but taking into consideration the the frequencey in which the client communicates to the server.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
loke6258038 wrote: to detect when a client on purpose power down his PC without closing the connection
There is no way to detect a client connection dropped without trying to contact it. If you write both client and server, you could implement some sort of "ping" or "heartbeat" functionality.
|
|
|
|
|
But the contacting the client from the server will not work if they are in different network where the ports are opened from only one side.Which will probably the typical case.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
If you are concerned with the client dropping the connection, this means that once the connection is opened, you can talk to the client.
I don't know the protocol you use, but I suspect it is custom. So, in your communication protocol, you could add a call where the server asks the client if he is still there after some idle time.
|
|
|
|
|
When you are closing the connection i.e when the user at the client closes the application call a function and indicate the server that the client is closing normally, on the form close method (if it is a winform) communicate to the server saying forced application close. You need to handle form close carefully because even under normal application close form close method gets triggered (this can be handled).
|
|
|
|
|
Hi,
In order to catch all cases, I would suggest a heartbeat function (as was already suggested). Some details (drawn from specs I've encountered interfacing with various industrial PLC systems):
- If your client sessions don't use persistent TCP connections (if you are using an HTTP request for each transaction, for example), you're correct in noting that you can't contact the client from the server gratuitously. In that case, have the client contact the server with a dummy message with a specific interval (unless it has already talked to the server during the interval) and let the server invalidate sessions that haven't been heard from in, say, twice that interval.
- If you do use persistent TCP connections (that stay open for the duration of the client session) you can contact the clients from the server (you can write to the socket from either direction as long as it's open). You could then send an "are you alive?"-message to clients you hadn't heard from in a while - you will get an exception if the TCP/IP stack has given up on the connection, a response if not and the client is alive, no response if the client is dead but the TCP/IP stack hasn't realized it yet. The benefit of this is that you can tune the timer intervals on the server without having to change or inform the clients.
Reasonable interval would be application specific, but beware of swamping the server with keep-alives if you could have a lot of clients.
One crane controller protocol I use requires keepalives be sent each minute (by both ends) and any party that hasn't heard anything for two minutes closes and gives up on the connection (if it's the client that gives up, it starts attempting to reconnect to the server - this also has a timeout and will be repeated indefinitely, as the protocol is built for stuff that should be connected at all times). Persistent TCP connections are used here.
Useful?
--
Peter
|
|
|
|
|
Thanks Peter..It is a good note.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
|
Look[^] what I found with google !!!
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|