1

I have a WPF app that uploads XML data to a web service asynchronously. I call the web service from a non-UI thread:

Task.Factory.StartNew(() => {
  WebServiceHelper.ImportMarketDataAsync(....);
});

I have generated the proxy using wsdl.exe. The proxy class provides two different ways to call the web service function asynchronously:

1) *MethodName*Async

2) Begin*MethodName* & End*MethodName*

The first method uses SoapHttpClientProtocol.InvokeAsync and the second method uses SoapHttpClientProtocol.BeginInvoke.

In either case, when the proxy hits the invoke function (i.e. InvokeAsync or BeginInvoke), the web service call is invoked from within the UI thread and therefore the application appears unresponsive since the UI thread is busy. If I call the async function in a foreach loop for a collection of say 250 elements, the UI will freeze until all async calls are complete.

Is there a way to call the asmx web service without blocking the main UI thread?

Thanks in advanced!

t.smith.htc
  • 203
  • 1
  • 3
  • 12
  • Afaik wpf is a replacement for asmx. You are using one or either. Asmx are nearly obsolete by today – Independent May 08 '12 at 21:56
  • Thanks for the comment Jonas. Did you mean WCF? – t.smith.htc May 08 '12 at 22:16
  • Yes, WCF of course. Though, is a side-note. I don't see if your problem is related to Webservice or if it's a problem with gui responsivity, which you can solve with starting the request in a new Thread instead of Task. – Independent May 09 '12 at 05:57
  • Unfortunately, I cannot control the technology of the web service. I tried starting the request in System.Threading.Thread instead of System.Threading.Tasks.Task and I get the same results. – t.smith.htc May 09 '12 at 12:52
  • Don't know if it solves the debugger blocking the threads issue but consider using FromAsync instead of StartNew. https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskfactory.fromasync – user3285954 Feb 05 '20 at 23:57

1 Answers1

0

When the application was attached to VS2010 for debugging, the UI would freeze. When I would run the application on its own, the application did not freeze. Something to do with the debugger.

t.smith.htc
  • 203
  • 1
  • 3
  • 12