473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how do I continue code while waiting for a response

hi
I make the following call
xmlResponse = xws.SubmitXml(Text, xmlRequest.DocumentElement,
xmlFilter.DocumentElement)

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 2482

"Adrian" <Ad****@nospamhotmail.com.uk> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
hi
I make the following call
xmlResponse = xws.SubmitXml(Text, xmlRequest.DocumentElement,
xmlFilter.DocumentElement)

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.Threading.Thread.Sleep(TimeSpan.FromSeconds (10))
Return "<hello/>"
End Function
End Class
Module Module1
Private Delegate Function SubmitXmlDelegate(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 SubmitXmlDelegate(AddressOf xyz.SumbitXml)
Console.WriteLine("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.WriteLine("Waiting...")
Loop While Not
waitObject.AsyncWaitHandle.WaitOne(TimeSpan.FromSe conds(1), False)

'Now we know execution is complete since WaitHandle.WaitOne
returned True
Dim rv As String = fp.EndInvoke(waitObject)

Console.WriteLine("Completed: " & rv)

Catch ex As Exception
Console.WriteLine(ex)

End Try

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

And working great.

WOW and thanks

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...

"Adrian" <Ad****@nospamhotmail.com.uk> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
hi
I make the following call
xmlResponse = xws.SubmitXml(Text, xmlRequest.DocumentElement,
xmlFilter.DocumentElement)

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.Threading.Thread.Sleep(TimeSpan.FromSeconds (10))
Return "<hello/>"
End Function
End Class
Module Module1
Private Delegate Function SubmitXmlDelegate(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 SubmitXmlDelegate(AddressOf xyz.SumbitXml)
Console.WriteLine("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.WriteLine("Waiting...")
Loop While Not
waitObject.AsyncWaitHandle.WaitOne(TimeSpan.FromSe conds(1), False)

'Now we know execution is complete since WaitHandle.WaitOne
returned True
Dim rv As String = fp.EndInvoke(waitObject)

Console.WriteLine("Completed: " & rv)

Catch ex As Exception
Console.WriteLine(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
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...
28
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...
3
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
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...
1
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...
0
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;...
3
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...
3
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...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.