|
|
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.
|
|
|
|
|
|
Hi all,
first of all, my Englisch's not my mothertongue, please forgive me mistakes in grammar.
Ok the Problem:
I have two DataTables:
- the first one, called FULL and contains all the relevant Information.
- the second one, called EXTRACT and is - the name say it - a extract from the FULL Table.
The User can made Inserts into the Extract Table on 3 ways:
- over a RichtTextBox
- over a Textbox
- with a NumericUpDown
And now my Idea was to make an Eventhandler, to update the FULL-Table evry Time the User made an Insert into the EXTRACT-Table.
I tried the ColumnChanged and the RowChanged Eventhandler, now comes a big BUT
everytime i clear the table and evry time when i fill an new Extract into the Table, the EventHandler throw an Event.
Cause of the Fact that the EXTRACT-Tables content is changing very often, i ask you:
Is there a possiblity to react only on userentrys?
Maybe there is a much more easier way to handle that
Hope on your answers
Greetz
Daniel
|
|
|
|
|
i'm not sure i understood so forgive me if my answer is not useful...but couldnt u just create a bool variable that according to its value the callback method will decide if to execute or not?
y
|
|
|
|
|
The idea isn't so bad, but let me tell you, how i load my Extract table and what my program did if i do that.
I load with a SQL script the Fulltable, thats not the problem.
But when i made a extract from the full table, sometimes there are more then 1000 records and for evry record there are 8 attributes, the program load 8000 times the eventhandler. small example
1 DataRow rw = table1.NewRow();
2 rw["Attribute"] = table2.Rows["row"]["Column"];
3 rw["Attribute"] = table2.Rows["row"]["Column"];
4 rw["Attribute"] = table2.Rows["row"]["Column"];
When i proceed Line 2 - 4, the Programm jumps 3 times into the EventHandler Function, why? I dont know.
And thats why i ask if there is a specific function to filter if it was a userentry or not.
|
|
|
|
|
Hi,
I am using a block of code to Import the Data to SQLServer2000
try
sqlTransaction sqlTran;
{
using (sqlTran = MyConnnection.BeginTansaction )
try
{
ImportData();
sqlTran.Commit();
}
catch(Exception ex)
{
sqlTran.Rollback()
}
}
catch
{}
Now as the Process start's If in middle of the Process I close the Window
the Process stop's, But the related tables in DB doesn't respond
Is that because rollback() is not called.If yes then Is it possible to calls Rollback in such situation.
Thanks
Navneet Hegde
Develop2Program & Program2Develop
|
|
|
|
|
Try putting the rollback and commit in a FINALLY block and set an indicator so you know which to execute. FINALLY blocks are always executed.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks
So, if I close my Application through Task maNager, Then before ending the process FINALLY will be executed.
Develop2Program & Program2Develop
|
|
|
|
|
I doubt that!
Why on earth do you want to close the application through the Task Manager?
|
|
|
|