A
awaken77
I have really annoying problem
My program polls Web Service in a loop many times, to retrieve some
"near-realtime" results. Usually once per 2-5 seconds.
To control call execution time, I use async calls with timeout.
Everything works fine, until Web Service hangs somewhere in-a-call ,
i.e. call never returns back from Web Service code.
The problem occurs when my code calls Web Service many many times ,
e.g. 3000 times and calls Abort() after each call
On CF 1.0 SP3 it throws ObjectDisposedException after program exits.
sometimes it throws 5 or 6 exceptions, after GUI shutdown.
On CF 2.0 it just hangs on exit when waiting for background threads to
be stopped.
Here is my code calling Web Service:
MyTimer timer = new MyTimer((ulong)m_proxy.timeout); // my timer class
try
{
timer.Reset();
m_handle = m_proxy.BeginRequest(paramsIn, null, null);
// Poll result until complete
while (!m_handle.IsCompleted && !timer.Check())
{
Thread.Sleep(5);
}
if (m_handle.IsCompleted)
{
m_ret = m_proxy.EndRequest(m_handle, out paramsOut);
}
else
{
((WebClientAsyncResult)m_handle).Abort();
throw new WebException("Timeout expired", null,
WebExceptionStatus.Timeout, null);
}
}
finally
{
timer = null; // not necessary
}
Here is my code to shutdown web service proxy, and cleanup resources
public void Close()
{
try
{
if(m_handle != null)
{
((WebClientAsyncResult)m_handle).Abort();
}
if(m_proxy != null)
{
m_proxy.Abort();
}
}
catch(Exception )
{
}
finally
{
m_handle = null;
m_proxy = null;
}
}
I call Close() from my polling thread, after this existing HTTP
connection should disconnect and thread should exit.
Instead, it throws exception
Instead polling for result I used Callback function, passed to
BeginRequest()
It ends up with worse result: when program terminates and WEbService
suddenly wakes up, WebService proxy internals call already disposed
callback object, with the same exception
I also tried Synchronous calls with Abort() on CF 1.0 SP3 - it ends up
with HUGE memory leak after running for 30 hours, and program ate all
system emmory
My program polls Web Service in a loop many times, to retrieve some
"near-realtime" results. Usually once per 2-5 seconds.
To control call execution time, I use async calls with timeout.
Everything works fine, until Web Service hangs somewhere in-a-call ,
i.e. call never returns back from Web Service code.
The problem occurs when my code calls Web Service many many times ,
e.g. 3000 times and calls Abort() after each call
On CF 1.0 SP3 it throws ObjectDisposedException after program exits.
sometimes it throws 5 or 6 exceptions, after GUI shutdown.
On CF 2.0 it just hangs on exit when waiting for background threads to
be stopped.
Here is my code calling Web Service:
MyTimer timer = new MyTimer((ulong)m_proxy.timeout); // my timer class
try
{
timer.Reset();
m_handle = m_proxy.BeginRequest(paramsIn, null, null);
// Poll result until complete
while (!m_handle.IsCompleted && !timer.Check())
{
Thread.Sleep(5);
}
if (m_handle.IsCompleted)
{
m_ret = m_proxy.EndRequest(m_handle, out paramsOut);
}
else
{
((WebClientAsyncResult)m_handle).Abort();
throw new WebException("Timeout expired", null,
WebExceptionStatus.Timeout, null);
}
}
finally
{
timer = null; // not necessary
}
Here is my code to shutdown web service proxy, and cleanup resources
public void Close()
{
try
{
if(m_handle != null)
{
((WebClientAsyncResult)m_handle).Abort();
}
if(m_proxy != null)
{
m_proxy.Abort();
}
}
catch(Exception )
{
}
finally
{
m_handle = null;
m_proxy = null;
}
}
I call Close() from my polling thread, after this existing HTTP
connection should disconnect and thread should exit.
Instead, it throws exception
Instead polling for result I used Callback function, passed to
BeginRequest()
It ends up with worse result: when program terminates and WEbService
suddenly wakes up, WebService proxy internals call already disposed
callback object, with the same exception
I also tried Synchronous calls with Abort() on CF 1.0 SP3 - it ends up
with HUGE memory leak after running for 30 hours, and program ate all
system emmory