Hi Paul,
Any further progress on this issue or does the suggestions in my former
messages helps a little? If there're any thing else we can help, please
feel free to post here.
Thanks & Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
X-Tomcat-ID: 160077421
References: <8B**********************************@microsoft.co m>
<11**********************@o13g2000cwo.googlegroups .com>
<D7**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_NextPart_0001_D359132B"
Content-Transfer-Encoding: 7bit
From:
st*****@online.microsoft.com (Steven Cheng[MSFT])
Organization: Microsoft
Date: Tue, 20 Sep 2005 09:24:16 GMT
Subject: Re: No return from async web service call
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Message-ID: <LR*************@TK2MSFTNGXA01.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
Lines: 333
Path: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.webservices:7949
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
Hi Paul,
Have you tried only using the CallBack handler, generally this is the most
recommend means in desktop applicaiton since it won't block your main UI
thread. Also, have you tried testing through a simple webmethod which will
take long time to run? Based on my local test, I can correctly get both
while(!ar.IsCompleted)
{
pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);
}
or using Callback handler means to work correctly. The only problem is
that when using while loop to poll the Complete status, the main UI thread
will be blocked from accepting other UI message gracefully.
Also, I've noticed that you're wanting to update the processbar constatly
during the long run webmethod processing, if so, I'm afraid CallBack hander
won't quite meet your requirement. Thus, spawn a new work thread to do the
work will be the best choice (if you won't spawn lots of such thread since
spawning a new thread is much more expensive than utilize threadpool
thread...). The code will be something like:
==================
private void btnCall_Click(object sender, System.EventArgs e)
{
System.Threading.Thread thread = new System.Threading.Thread(new
System.Threading.ThreadStart(CallWS_Proc));
thread.Start();
}
private void CallWS_Proc()
{
DocService.DocService ds = new WSClient.DocService.DocService();
ds.Credentials = System.Net.CredentialCache.DefaultCredentials;
IAsyncResult ar = ds.BeginDummyUpload(null,null, ds);
while(!ar.IsCompleted)
{
//call function to update the UI
pbTime.Increment(5);
System.Threading.Thread.Sleep(1000);
}
string ret = ds.EndDummyUpload(ar);
}
If there're anything else we can help, please feel free to post here.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
Thread-Topic: No return from async web service call
thread-index: AcW89ZW8tjUj7CXhR5y2bwnyuA6mlQ==
X-WBNR-Posting-Host: 62.6.144.66
From: "=?Utf-8?B?UGF1bCBIYXNlbGw=?=" <pa*********@community.nospam>
References: <8B**********************************@microsoft.co m>
<11**********************@o13g2000cwo.googlegroups .com>
Subject: Re: No return from async web service call
Date: Mon, 19 Sep 2005 01:39:01 -0700
Lines: 80
Message-ID: <D7**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
microsoft.public.dotnet.framework.webservices:7932
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
Peter,
Thanks, that would explain a lot. The idea of the infinite loop is to try
and fake an upload progress bar so the user doesn't think it's frozen if
the
upload takes a while (our users can get very twitchy). I had tried using
just
the IsCompleted without a callback but that didn't seem to be getting set
either!? I may have to to cheat and use a synchronous call on the main
thread
and spin the progress bar onto another thread instead, not elegant but at
least functional.
"Peter K" wrote:
Hi Paul,
I have to admit that my thread knowledge has gotten pretty rusty, but
I think that even though your webservice will run on new thread, the
thread your callback will run on is the same thread that your
btnUpload_click method will be running on. Therefore UploadHandler
won't be able to run until btnUpload_click method has completed. Since
you have infinite loop running in there, UploadHandler will just keep
waiting and won't fire.
I managed to replicate the same behaviour you are experiencing using a
continual while loop. When I removed the while loop, your code worked
fine.
Hope that helps
Peter Kelcey
Paul Hasell wrote: Hi,
I'm trying to invoke a web method asynchronously but just can't seem to
get it to tell me when it has finished! Below is the code I am (currently)
using:
private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
SOPWebService.Client uploader = new
GLTUpload.SOPWebService.Client();
uploader.Credentials =
System.Net.CredentialCache.DefaultCredentials;
IAsyncResult async_upload =
uploader.BeginUploadDirect(txtKeyAccountTeam.Selec tedValue.ToString(),
_xml_content, new AsyncCallback(UploadHandler), uploader);
while(!async_upload.IsCompleted)
{
Thread.Sleep(1000);
Progress.Increment(1);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}
private void UploadHandler(IAsyncResult async_result)
{
SOPWebService.Client sop_web_client = (SOPWebService.Client)
async_result.AsyncState;
sop_web_client.EndUploadDirect(async_result);
}
The problem is that although the web method is invoked, executes and
ends the callback never gets fired and the IAsyncResult never has it's
IsCompleted set to true.
Anyone know what I'm missing?