|
Why don't you use a generic list? When you add a new item, simply remove the 0th one.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Now that would not be very efficient! But it will work
|
|
|
|
|
leppie wrote: Now that would not be very efficient! But it will work
All the good answers were taken.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
HAHAHA
|
|
|
|
|
There is no need to rebuild an array each time.U do one thing u take stringbuilder class's object and use it. Which will allow you to take an array of any length.
Bhumika
|
|
|
|
|
Hi,
I'm during numerical calculations here. The array is comprised of doubles and not strings.
Regards,
Dave
|
|
|
|
|
hi friend i want to add windows service but this time i want to add it using C# code can any body have tell me how i can do that or there is no way to that
wasim khan
|
|
|
|
|
|
|
Hello everyone,
I have made tests, just want to confirm here since I am new to this method.
1.
HttpListener.BeginGetContext is never blocked?
2.
If we wait on the handle, like this, then the wait handle will be signalled immediately when we call EndGetContext, like this "listener.EndGetContext(result)"?
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback),listener);
result.AsyncWaitHandle.WaitOne();
thanks in advance,
George
|
|
|
|
|
George_George wrote: HttpListener.BeginGetContext is never blocked?
Methods starts with BeginXXX are considered to be assynchronous and won't block.
2 - I guess you won't be able to call EndGetContext() until the operation finishes as result.AsyncWaitHandle.WaitOne(); blocks.
|
|
|
|
|
Thanks ForumExpertOnLine,
I am confused why I can not call EndGetContext? I think I am free to call it at any time. I have posted my code here to clarify.
In my code, I pass a delegate as the 1st parameter for method BeginGetContext as callback when a client request is available, and in the callback, I call EndGetContext.
Could you clarify what do you mean "won't be able to call EndGetContext()" please?
http://www.codeproject.com/script/Forums/View.aspx?fid=1649&select=2582942&tid=2580144[^]
regards,
George
|
|
|
|
|
George_George wrote: why I can not call EndGetContext? I think I am free to call it at any time.
1 - It calls BeginGetContext() which immediatly returns with a IAsyncResult instance.
2 - You are calling WaitOne() on this, which will block the thread until it gets a signal. It gets a signal when the processing is over. That is why you are not able to call EndGetContext until it finishes the operation.
|
|
|
|
|
Thanks N a v a n e e t h!
"when the processing is over" -- what processing? You mean receiving an underlying client Http request from socket layer or the processing of the delegate as the first parameter I passed to BeginGetContext or something else?
regards,
George
|
|
|
|
|
George_George wrote: what processing?
Until BeginGetContext() finishes.
|
|
|
|
|
Thanks N a v a n e e t h,
1.
You mean if we provide a callback as the first parameter to BeginGetContext, then the asynchronous operation will be done at first, until it is completed, the callback is called and we are able to call EndGetContext, correct?
(I think it is a general description of how asynchronous call works in C#)
2.
What is the underlying work between we begin to call BeginGetContext and the callback is called?
regards,
George
|
|
|
|
|
1 - yes. so you shouldn't call waitone just down to BeginGetContext call.
2 - Obviously it uses a thread pool thread and begin processing. When it finishes, it calls back.
|
|
|
|
|
Thanks N a v a n e e t h!
1.
"shouldn't call waitone just down to BeginGetContext call" -- sorry my English is not good. Could you show me some pseudo code please? I do not understand what means "just down to".
2.
N a v a n e e t h wrote: Obviously it uses a thread pool thread and begin processing. When it finishes, it calls back.
I think the underlying thread pool work is to receiving Http request and package into HttpListenerContext data structure?
regards,
George
|
|
|
|
|
1 -
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback),listener);
result.AsyncWaitHandle.WaitOne();
|
|
|
|
|
I agree, thanks N a v a n e e t h!
1.
When the asynchronous I/O operations completes (not when we call EndGetContext), the handle on the WaitOne will be singalled. Right?
2.
I have the question 1 because you mentioned -- "It blocks until listener.BeginGetContext finishes". I think BeginGetContext is not blocking and will return immediately, and we should say -- It blocks until the asynchronous I/O operation triggered by listener.BeginGetContext finishes? Correct?
regards,
George
|
|
|
|
|
|
Thanks N a v a n e e t h!
I did some further testing and study.
1. I think BeginGetContext will call the customized callback immediately even if there is no underlying TCP client?
2. I think the wait handle will be signalled immediately when there is an underlying TCP client connection even if we do not call EndfGetContext (so no relationship between calling EndGetContext and the wait handle signal be set)?
3. And EndGetContext will also be blocked until a TCP client connection is ready?
regards,
George
|
|
|
|
|
George_George wrote: . I think the wait handle will be signalled immediately when there is an underlying TCP client connection even if we do not call EndfGetContext (so no relationship between calling EndGetContext and the wait handle signal be set)?
I don't think so. WaitHandle will be signaled when the asynchronous operations ends.
|
|
|
|
|
Thanks N a v a n e e t h,
Do you think asynchronous operations is the same thing as the callback method? If not, could you clarify please?
regards,
George
|
|
|
|
|
George_George wrote: Do you think asynchronous operations is the same thing as the callback method?
CallBack method ? They are implemented using delegates. Asynchronous methods are different. They are used to do a job without blocking any thread hence it consumes better CPU.
|
|
|
|