Asynchronus WebService call Progress Bar

I have a WebMethod that I'd like to call asynchronusly and be able to display a Progress Bar. What's being sent to the WebMethod on the WebService is a byte array.

I'm fairly new to asynchronus calls and was wondering if this is possible before I dive in looking. Thanx! :)

[279 byte] By [codefund.com] at [2007-12-16]
# 1
Of course it's possible. Isn't everything possible with .Net? ;)

Check out this article: <a href=" http://msdn.microsoft.com/library/en-us/dnservice/html/service09032002.asp"></a>

Will that help you get started?

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Of course it's possible. Isn't everything possible with .Net? ;)

Check out this article: <a href="http://msdn.microsoft.com/library/en-us/dnservice/html/service09032002.asp">Asynchronous Web Service Calls over HTTP with the .NET Framework</a>

Will that help you get started?

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
I've read stuff like that and understand how to make an asynchronus call and have it return when it's done, etc, but I don't see anywhere, where it explains how you can get a progress, but I'm a horrible reader, so it might be right in front of my face. I'll read through that one and see what I find. Thanx for the link!
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
I have been wondering the same. For the individuals who do not know already, Erik and I had a previous conversation regarding web applications utilizing a progress bar. I had asked Erik about hosting Windows Forms from within IE thinking that might do the trick. He said that I would be looking more towards an HTTP Module.

So, I would actually recommend taking this idea and asking over in the ASP.Net Forums. I have already posted a message about this here: <a href="http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=179538">ASP.Net Forums - Post 179538</a>.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
The problem is that when you call a Web Service asynchronously, it only (by default) calls back when it's complete. Want a reasonable solution? Do what most apps do--most apps haven't a clue when the called process will complete. They get the progress meter going based on a timer, then in the callback from the web method, clear the progress meter. If you fill the progress meter, start over from the beginning.

Here's a lame-o example of doing this. Really, all users need is indication of progress, for the most part. Although you might be able to work out some sort of regularly-timed callback from the service, is that really worth it?
Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents tmrProgress As System.Windows.Forms.Timer
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents tmrService As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.tmrProgress = New System.Windows.Forms.Timer(Me.components)
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar()
Me.Button1 = New System.Windows.Forms.Button()
Me.tmrService = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
'
'tmrProgress
'
Me.tmrProgress.Interval = 50
'
'ProgressBar1
'
Me.ProgressBar1.Location = New System.Drawing.Point(16, 64)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(296, 23)
Me.ProgressBar1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(168, 40)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Run Web Service"
'
'tmrService
'
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(320, 101)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.ProgressBar1})
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub tmrProgress_Tick( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles tmrProgress.Tick
UpdateProgress(ProgressBar1)
End Sub

Private Sub UpdateProgress(ByVal pb As ProgressBar)
pb.Value = (pb.Value + 1) Mod pb.Maximum
End Sub

Private Sub ClearProgress(ByVal pb As ProgressBar)
tmrProgress.Enabled = False
pb.Value = pb.Minimum
End Sub

Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
tmrProgress.Enabled = True

' Emulate a long-running process. Fake a
' service that runs for 10 seconds.
tmrService.Interval = 10000
tmrService.Enabled = True
End Sub

Private Sub tmrService_Tick( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles tmrService.Tick
ClearProgress(ProgressBar1)
End Sub
End Class

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
yah, i guess it's probably not even worth it. I guess I'll just stick with my original idea of having a popup that says "Uploading..." and has a cancel button. :(
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7
Well, having a progress bar (which, as you see, is awfully trivial) is better than nothing, if it's going to take longer than a few seconds.

The question is: How do you safely cancel the asynch web method?

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
I was assuming I could use WebClientAsyncResult.Abort, but haven't actually tried it yet, so we'll see! ;)
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 9
Ken,

What would you suggest for a database call then, the same?

Jason

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 10
Unless the database provides a callback mechanism by which they provide feedback (and there aren't many that do), this is a viable solution. It's certainly the one most people use, when they can't determine the status of discrete operations.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...