473,669 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I continue code while waiting for a response

hi
I make the following call
xmlResponse = xws.SubmitXml(T ext, xmlRequest.Docu mentElement,
xmlFilter.Docum entElement)

It returns what I want but I would like to do a "do while loop" while I wait
for the response 2- 10 secs so I can place some graphic or some thing to
show its not locked up...

How would I change the call to do this?

thanks
Nov 21 '05 #1
2 2490

"Adrian" <Ad****@nospamh otmail.com.uk> wrote in message
news:db******** **@nwrdmz03.dmz .ncs.ea.ibs-infra.bt.com...
hi
I make the following call
xmlResponse = xws.SubmitXml(T ext, xmlRequest.Docu mentElement,
xmlFilter.Docum entElement)

It returns what I want but I would like to do a "do while loop" while I
wait for the response 2- 10 secs so I can place some graphic or some thing
to show its not locked up...


Ok. You need a Delegate.

A Delegate is an object that wraps a function call. Among the many uses of
Delegates, is that they can be invoked either Sync or Async.

Often when invoking a Delegate you use a callback function, but you don't
have to. You can just wait for it to complete while doing other work.

Here's how:

Create a Delegate Type matching the method signature of xws.SubmitXML.
Then create a new delegate instance, refering to xws.SubmitXML.
Then call BeginInvoke, Get an IAsyncResult, do whatever, use the WaitHandle
to "listen" for completion, then call EndInvoke.

Ok, that sounds hard, but it's really not. Here's a complete working
example:

Class XYZ
Public Function SumbitXml(ByVal Text As String, _
ByVal doc As Xml.XmlElement, _
ByVal filter As Xml.XmlElement) As String
'simulate long-running method
System.Threadin g.Thread.Sleep( TimeSpan.FromSe conds(10))
Return "<hello/>"
End Function
End Class
Module Module1
Private Delegate Function SubmitXmlDelega te(ByVal Text As String, _
ByVal doc As Xml.XmlElement,
_
ByVal filter As
Xml.XmlElement) As String

Sub Main()
Try
Dim xyz As New XYZ
Dim fp As New SubmitXmlDelega te(AddressOf xyz.SumbitXml)
Console.WriteLi ne("About to BeginInvoke")
Dim doc As Xml.XmlElement = Nothing
Dim filter As Xml.XmlElement = Nothing

'Start running funtion on a background thread. No need for a
callback function or state object.
Dim waitObject As IAsyncResult = fp.BeginInvoke( "", doc, filter,
Nothing, Nothing)

'Wait for it to complete
Do
Console.WriteLi ne("Waiting..." )
Loop While Not
waitObject.Asyn cWaitHandle.Wai tOne(TimeSpan.F romSeconds(1), False)

'Now we know execution is complete since WaitHandle.Wait One
returned True
Dim rv As String = fp.EndInvoke(wa itObject)

Console.WriteLi ne("Completed: " & rv)

Catch ex As Exception
Console.WriteLi ne(ex)

End Try

End Sub
End Module
Nov 21 '05 #2
Absolutely incredible!!!!!

And working great.

WOW and thanks

"David Browne" <davidbaxterbro wne no potted me**@hotmail.co m> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..

"Adrian" <Ad****@nospamh otmail.com.uk> wrote in message
news:db******** **@nwrdmz03.dmz .ncs.ea.ibs-infra.bt.com...
hi
I make the following call
xmlResponse = xws.SubmitXml(T ext, xmlRequest.Docu mentElement,
xmlFilter.Docum entElement)

It returns what I want but I would like to do a "do while loop" while I
wait for the response 2- 10 secs so I can place some graphic or some
thing to show its not locked up...


Ok. You need a Delegate.

A Delegate is an object that wraps a function call. Among the many uses
of Delegates, is that they can be invoked either Sync or Async.

Often when invoking a Delegate you use a callback function, but you don't
have to. You can just wait for it to complete while doing other work.

Here's how:

Create a Delegate Type matching the method signature of xws.SubmitXML.
Then create a new delegate instance, refering to xws.SubmitXML.
Then call BeginInvoke, Get an IAsyncResult, do whatever, use the
WaitHandle to "listen" for completion, then call EndInvoke.

Ok, that sounds hard, but it's really not. Here's a complete working
example:

Class XYZ
Public Function SumbitXml(ByVal Text As String, _
ByVal doc As Xml.XmlElement, _
ByVal filter As Xml.XmlElement) As String
'simulate long-running method
System.Threadin g.Thread.Sleep( TimeSpan.FromSe conds(10))
Return "<hello/>"
End Function
End Class
Module Module1
Private Delegate Function SubmitXmlDelega te(ByVal Text As String, _
ByVal doc As
Xml.XmlElement, _
ByVal filter As
Xml.XmlElement) As String

Sub Main()
Try
Dim xyz As New XYZ
Dim fp As New SubmitXmlDelega te(AddressOf xyz.SumbitXml)
Console.WriteLi ne("About to BeginInvoke")
Dim doc As Xml.XmlElement = Nothing
Dim filter As Xml.XmlElement = Nothing

'Start running funtion on a background thread. No need for a
callback function or state object.
Dim waitObject As IAsyncResult = fp.BeginInvoke( "", doc,
filter, Nothing, Nothing)

'Wait for it to complete
Do
Console.WriteLi ne("Waiting..." )
Loop While Not
waitObject.Asyn cWaitHandle.Wai tOne(TimeSpan.F romSeconds(1), False)

'Now we know execution is complete since WaitHandle.Wait One
returned True
Dim rv As String = fp.EndInvoke(wa itObject)

Console.WriteLi ne("Completed: " & rv)

Catch ex As Exception
Console.WriteLi ne(ex)

End Try

End Sub
End Module

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3933
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a test on it that if the network broken at the time the client have already send the remoting request and waiting for the server, the client side will wait infinitely by default, even if i already set the executionTimeout to 90seconds in...
28
5075
by: n00m | last post by:
When I double-click on "some.py" file console window appears just for a moment and right after that it's closed. If this script is started from inside of IDLE (F5 key) then it executes as it should be (e.g. executing all its print statements). Any ideas? OS: Windows; Python 2.3.4. Thanks.
3
6596
by: JM | last post by:
Newbie Question Is there a way to use Message.Show so that it will allow the program to continue processing without waiting for a user to click OK?
0
1546
by: Xavier Osa | last post by:
Hi, I have an ASP.Net web page that you can download a file. As Fergunson's problem, it prompts twice dialog boxes only if I select Open button. If I select Save button, it prompts once. I'm using W2000KS & IE6 sp1 & VS.NET 2003. If I change method="post" by method="get" form attribute, it works fine.
1
2223
by: Chris | last post by:
Hi, how can I send information that is in the Response.OutputStream to the client but continue server processing without having to close the page , or without having to Reponse.End() the application ? I tried Response.OutputStream.Flush(); but it doesn't seem to work, only when I follow it with a Reponse.End() , but that's then gonna stop the server processing what is what I don't want. Here's my problem : in a button-event handler
0
1355
by: volcovcommander | last post by:
I'm experiencing what looks like an http 1.1 100 continue issue with IE 6, IIS 6 and an ASP.NET app. The scenario is such: - I send POST request to page A which then should redirect to page B; - the response contains 302 to page B + standard redirect html body + whatever page A have managed to render before redirect. in some cases at the very end of response data (after the closing html
3
14532
by: Christian Lutz | last post by:
Hy there I have a Web Services written in Java, running on Tomcat. The Client is written in C#. When i monitor the request/Response with TCPMon (included in Tomcat) i can observer the following sequence: ******************************************** CLIENT:: Request ********************************************
3
2179
by: Jamie Risk | last post by:
I'm attempting to improve some serially executing code (that uses the SerialPort class) bogging Windows down when it runs. To do the 'antibogging' I'm following the example from MSDN Windows.IO.Ports.SerialPort page and use threading. I'm not sure if I'm creating problems with this implementation and would appreciate your input. The original serial code: {
2
4173
by: boole | last post by:
Hi there, when my ASP page receives the client request, I want to gather the request data (form), promptly end the response to the client (successful) and continue doing what I need to do with the data, the result of which does not affect the response, hence why i don't want to waste time leaving the connection open or keeping the client waiting, I suppose you could call the client request a "trigger". I do not mind using ASP functions...
0
8894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8587
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.