By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Forcefully aborting asychronous call.

P: n/a
Hi all,

I am having application in which i am doing asynchronous call.I am
using manualresetevent to wait for asynchronous call to complete.

I want to stop asynchronous call after certain period of time.

I want something like thread.abort for aborting aynchronous call.

Can someone tell me way of aborting asynchronous call.

Any help will be truely appreciated.

thanks in advance.

Aug 21 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
ManualResetEvent.WaitOne() has three overloads, two of which take a
timeout parameter as either an int (milliseconds) or TimeSpan.

Also you could call Set() yourself from a different thread if
something happens that causes you not to want to wait any more--the
waiting code will continue execution just like the wait had timed out.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.


On 21 Aug 2006 00:22:06 -0700, "archana" <tr**************@yahoo.com>
wrote:
>Hi all,

I am having application in which i am doing asynchronous call.I am
using manualresetevent to wait for asynchronous call to complete.

I want to stop asynchronous call after certain period of time.

I want something like thread.abort for aborting aynchronous call.

Can someone tell me way of aborting asynchronous call.

Any help will be truely appreciated.

thanks in advance.
Aug 21 '06 #2

P: n/a
Hi,

thanks for your reply.

In method i am calling set method at the end of whole procedure.

But what i want is if process is not completed say withing 2 mins then
i need to forcefully abort it. So i called waitone on event with
passing time as 2 mins.

So My question is after waitone will that function continue its
execution.

Means like if we call thread.abort it stop execution of thread, is
there any similar functionlity for asychrnonous call abort.

Any help will be truely appreciated.

Thanks
Samuel R. Neff wrote:
ManualResetEvent.WaitOne() has three overloads, two of which take a
timeout parameter as either an int (milliseconds) or TimeSpan.

Also you could call Set() yourself from a different thread if
something happens that causes you not to want to wait any more--the
waiting code will continue execution just like the wait had timed out.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.


On 21 Aug 2006 00:22:06 -0700, "archana" <tr**************@yahoo.com>
wrote:
Hi all,

I am having application in which i am doing asynchronous call.I am
using manualresetevent to wait for asynchronous call to complete.

I want to stop asynchronous call after certain period of time.

I want something like thread.abort for aborting aynchronous call.

Can someone tell me way of aborting asynchronous call.

Any help will be truely appreciated.

thanks in advance.
Aug 22 '06 #3

P: n/a
Please try to answer following questions: what exactly is your async. call
doing and more importantly - why does it not return in a timely fashion.
If your call has transitioned into unmanaged code (say a synch. socket call
or any other blocking call), and this unmanaged function waits for an IO
completion which never happens, you are stuck. In this scenario, even a
Thread.Abort will not terminate the thread, as Thread.Abort cannot abort a
thread that is executing outside the CLR. All you can do in such case is
unload the Application domain, or terminate the process, Thread.Abort is
never a solution and is only applicable if you are going to throw away the
AD anyway.

Willy.
"archana" <tr**************@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
| Hi,
|
| thanks for your reply.
|
| In method i am calling set method at the end of whole procedure.
|
| But what i want is if process is not completed say withing 2 mins then
| i need to forcefully abort it. So i called waitone on event with
| passing time as 2 mins.
|
| So My question is after waitone will that function continue its
| execution.
|
| Means like if we call thread.abort it stop execution of thread, is
| there any similar functionlity for asychrnonous call abort.
|
| Any help will be truely appreciated.
|
| Thanks
| Samuel R. Neff wrote:
| ManualResetEvent.WaitOne() has three overloads, two of which take a
| timeout parameter as either an int (milliseconds) or TimeSpan.
| >
| Also you could call Set() yourself from a different thread if
| something happens that causes you not to want to wait any more--the
| waiting code will continue execution just like the wait had timed out.
| >
| HTH,
| >
| Sam
| >
| >
| >
| ------------------------------------------------------------
| We're hiring! B-Line Medical is seeking Mid/Sr. .NET
| Developers for exciting positions in medical product
| development in MD/DC. Work with a variety of technologies
| in a relaxed team environment. See ads on Dice.com.
| >
| >
| >
| >
| On 21 Aug 2006 00:22:06 -0700, "archana" <tr**************@yahoo.com>
| wrote:
| >
| Hi all,
|
| I am having application in which i am doing asynchronous call.I am
| using manualresetevent to wait for asynchronous call to complete.
|
| I want to stop asynchronous call after certain period of time.
|
| I want something like thread.abort for aborting aynchronous call.
|
| Can someone tell me way of aborting asynchronous call.
|
| Any help will be truely appreciated.
|
| thanks in advance.
|
Aug 22 '06 #4

P: n/a
Hi,

thanks for your reply.

I am calling begingGetresponse method of webrequest asynchronously.
Actually i am calling 5 begingetresponse at a time to proess 5 urls and
i want all 5 to gets aborted depending on option selected.

I set timeout for this using registerwaitforsingleobject but this is
not working properly.

I want to abort this asynchronous call.

How can i do this?

thanks in advance.

Willy Denoyette [MVP] wrote:
Please try to answer following questions: what exactly is your async. call
doing and more importantly - why does it not return in a timely fashion.
If your call has transitioned into unmanaged code (say a synch. socket call
or any other blocking call), and this unmanaged function waits for an IO
completion which never happens, you are stuck. In this scenario, even a
Thread.Abort will not terminate the thread, as Thread.Abort cannot abort a
thread that is executing outside the CLR. All you can do in such case is
unload the Application domain, or terminate the process, Thread.Abort is
never a solution and is only applicable if you are going to throw away the
AD anyway.

Willy.
"archana" <tr**************@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
| Hi,
|
| thanks for your reply.
|
| In method i am calling set method at the end of whole procedure.
|
| But what i want is if process is not completed say withing 2 mins then
| i need to forcefully abort it. So i called waitone on event with
| passing time as 2 mins.
|
| So My question is after waitone will that function continue its
| execution.
|
| Means like if we call thread.abort it stop execution of thread, is
| there any similar functionlity for asychrnonous call abort.
|
| Any help will be truely appreciated.
|
| Thanks
| Samuel R. Neff wrote:
| ManualResetEvent.WaitOne() has three overloads, two of which take a
| timeout parameter as either an int (milliseconds) or TimeSpan.
| >
| Also you could call Set() yourself from a different thread if
| something happens that causes you not to want to wait any more--the
| waiting code will continue execution just like the wait had timed out.
| >
| HTH,
| >
| Sam
| >
| >
| >
| ------------------------------------------------------------
| We're hiring! B-Line Medical is seeking Mid/Sr. .NET
| Developers for exciting positions in medical product
| development in MD/DC. Work with a variety of technologies
| in a relaxed team environment. See ads on Dice.com.
| >
| >
| >
| >
| On 21 Aug 2006 00:22:06 -0700, "archana" <tr**************@yahoo.com>
| wrote:
| >
| Hi all,
|
| I am having application in which i am doing asynchronous call.I am
| using manualresetevent to wait for asynchronous call to complete.
|
| I want to stop asynchronous call after certain period of time.
|
| I want something like thread.abort for aborting aynchronous call.
|
| Can someone tell me way of aborting asynchronous call.
|
| Any help will be truely appreciated.
|
| thanks in advance.
|
Aug 22 '06 #5

P: n/a


"archana" <tr**************@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
| Hi,
|
| thanks for your reply.
|
| I am calling begingGetresponse method of webrequest asynchronously.
| Actually i am calling 5 begingetresponse at a time to proess 5 urls and
| i want all 5 to gets aborted depending on option selected.
|
| I set timeout for this using registerwaitforsingleobject but this is
| not working properly.
|
| I want to abort this asynchronous call.
|
| How can i do this?
|
| thanks in advance.
|

RegisterWaitForSingleObject should work, can you please post a complete
samle that illustrates the issue?

Willy.
Aug 22 '06 #6

P: n/a
The new CCR is very well suited for this kind or arbitration. The runtime
is used in their new robotics stuff as that is heavily threaded. It is not
RTM yet, but the current bits work great. It is worth playing with anyway
and getting to know the Port<Tabstraction.
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

--
William Stacey [MVP]

"archana" <tr**************@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
| Hi,
|
| thanks for your reply.
|
| I am calling begingGetresponse method of webrequest asynchronously.
| Actually i am calling 5 begingetresponse at a time to proess 5 urls and
| i want all 5 to gets aborted depending on option selected.
|
| I set timeout for this using registerwaitforsingleobject but this is
| not working properly.
|
| I want to abort this asynchronous call.
|
| How can i do this?
|
| thanks in advance.
|
| Willy Denoyette [MVP] wrote:
| Please try to answer following questions: what exactly is your async.
call
| doing and more importantly - why does it not return in a timely fashion.
| If your call has transitioned into unmanaged code (say a synch. socket
call
| or any other blocking call), and this unmanaged function waits for an IO
| completion which never happens, you are stuck. In this scenario, even a
| Thread.Abort will not terminate the thread, as Thread.Abort cannot abort
a
| thread that is executing outside the CLR. All you can do in such case is
| unload the Application domain, or terminate the process, Thread.Abort is
| never a solution and is only applicable if you are going to throw away
the
| AD anyway.
| >
| Willy.
| >
| >
| "archana" <tr**************@yahoo.comwrote in message
| news:11**********************@m73g2000cwd.googlegr oups.com...
| | Hi,
| |
| | thanks for your reply.
| |
| | In method i am calling set method at the end of whole procedure.
| |
| | But what i want is if process is not completed say withing 2 mins then
| | i need to forcefully abort it. So i called waitone on event with
| | passing time as 2 mins.
| |
| | So My question is after waitone will that function continue its
| | execution.
| |
| | Means like if we call thread.abort it stop execution of thread, is
| | there any similar functionlity for asychrnonous call abort.
| |
| | Any help will be truely appreciated.
| |
| | Thanks
| | Samuel R. Neff wrote:
| | ManualResetEvent.WaitOne() has three overloads, two of which take a
| | timeout parameter as either an int (milliseconds) or TimeSpan.
| | >
| | Also you could call Set() yourself from a different thread if
| | something happens that causes you not to want to wait any more--the
| | waiting code will continue execution just like the wait had timed
out.
| | >
| | HTH,
| | >
| | Sam
| | >
| | >
| | >
| | ------------------------------------------------------------
| | We're hiring! B-Line Medical is seeking Mid/Sr. .NET
| | Developers for exciting positions in medical product
| | development in MD/DC. Work with a variety of technologies
| | in a relaxed team environment. See ads on Dice.com.
| | >
| | >
| | >
| | >
| | On 21 Aug 2006 00:22:06 -0700, "archana"
<tr**************@yahoo.com>
| | wrote:
| | >
| | Hi all,
| |
| | I am having application in which i am doing asynchronous call.I am
| | using manualresetevent to wait for asynchronous call to complete.
| |
| | I want to stop asynchronous call after certain period of time.
| |
| | I want something like thread.abort for aborting aynchronous call.
| |
| | Can someone tell me way of aborting asynchronous call.
| |
| | Any help will be truely appreciated.
| |
| | thanks in advance.
| |
|
Aug 22 '06 #7

P: n/a
hi,

thanks for your reply.

I am having following function to create request

public static System.IAsyncResult MakeHttpRequest(string str)
{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str);
req.Timeout = 600;
System.IAsyncResult ar = req.BeginGetResponse(new
AsyncCallback(AfterExecution), req);

return ar;
}

public static void AfterExecution(System.IAsyncResult ar)
{
// Return the response.
HttpWebRequest req = (HttpWebRequest) ar.AsyncState;
HttpWebResponse resp = (HttpWebResponse) req.EndGetResponse(ar);

//Wrap the response stream with a text-based reader
StreamReader sr = new StreamReader(resp.GetResponseStream());

string strStream = sr.ReadToEnd();

// Close the response to free resources.
sr.Close();
resp.Close();
System.Console.WriteLine("after execution reach here for " +
resp.ResponseUri.ToString());
}

in main code i am doing following things:-
System.IAsyncResult ar1 = MakeHttpRequest("http://www.msdfdn.com");
System.IAsyncResult ar2 = MakeHttpRequest"http://www.yadfdhoo.com");
WaitHandle[] wh = {ar1.AsyncWaitHandle,ar2.AsyncWaitHandle};
if (WaitHandle.WaitAll(wh, 10, false))
{
console.writeline(''break');
}
So my question is will afterexecution function execute if i called
waithandle.waitall for 10 sec as i set timeout as 600.

I read on msdn that when you are calling asynchronous webrequest
tiemout property doesn't work so i added registeredtimeout to set
timeout for asynchronous webrequest.

My second question if i want to execute different function on timeout,
means say after calling waithandle.waitall if call doesn;t completed
within that time i want some different processing so i wrote another
function and called that function with passing one parameter that is
ar1 or ar2. And in that function i called endwebresponse.

Will it clash with 'afterexecution' function?

And if i set timeout using registedwaitforobject with timeout say 100
seconds but in waithandle.waitlall i set timeout to 10 which will gets
consider.

Please correct me if i am wrong.
Thanks.


Willy Denoyette [MVP] wrote:
"archana" <tr**************@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
| Hi,
|
| thanks for your reply.
|
| I am calling begingGetresponse method of webrequest asynchronously.
| Actually i am calling 5 begingetresponse at a time to proess 5 urls and
| i want all 5 to gets aborted depending on option selected.
|
| I set timeout for this using registerwaitforsingleobject but this is
| not working properly.
|
| I want to abort this asynchronous call.
|
| How can i do this?
|
| thanks in advance.
|

RegisterWaitForSingleObject should work, can you please post a complete
samle that illustrates the issue?

Willy.
Aug 23 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.