472,805 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Forcefully aborting asychronous call.

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
7 6742
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
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
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
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


"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason | last post by:
I have a job created on my server which runs a stored procedure. The SP uses a cursor on a recordset to insert rows into a table (via a stored procedure - hence the cursor). It is expected that...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
2
by: Xarky | last post by:
Hi, I am writing a small program, that makes use of threads. Now in on of the threads I have a critical section, where I am using the Monitor to handle this. *** Thread_1 *** started for(...)...
7
by: trialproduct2004 | last post by:
Hi all I am having application in c# where i am loading one table of database into dataset. My table is of large size. so whenever i am loading that into dataset my memory size is getting...
1
by: SenthilVel | last post by:
Hi all i have a requirement in my application where in need to call a web service: 1. My client calls my webservice . 2. when i receive a call from my web servcie i need to notify my client...
4
by: Mufasa | last post by:
Is there any way to force a thread to abort and really have it abort? I have a thread that every once in a while gets hung to so I kill it. Problem is I have a thread that every once in a while...
2
by: William Johnston | last post by:
Hello, I need to perform synchronous calls to a DllImport function that is asychronous. (The Dllmport function returns immediately.) So far I have a timer that waits inside a ThreadPool queue....
3
by: AdrianDev | last post by:
Hi, I have a thread which I call like this: // Allocate a new thread containing class with the host getInfoThread git = new getInfoThread(host); // Create the thread and call the Go method...
0
by: spearlselvam | last post by:
Hi all, I have created a chat appln using asychronous socket.. can anyone say the diff of using the below code snippet 1. SetControlProperty(conStatus, "Text", receivedData); ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.