-
Progress bar on COM
Hi,
I'm using ATL (VC++) to create a COM server. In order to see the progress
of the execution, i will needs a progress bar.
Is there any way to have a progress bar on the server side (VC++)that i can
get from the client side (using VB)?
thanks
Jeff Aziz
-
Re: Progress bar on COM
This is a difficult problem to solve. If this weren't a distributed application,
you could let your processing object raise events with its status. The progress
bar would trap the events and update the display. However, because this is
a distributed application, you can't use events or other forms of callbacks
(e.g., passing a handle to the progress bar to the processing routine and
have it update it) except in special situations where you have complete control
over the clients.
The problem is server's are only allowed to send to the client when the method
ends (returns). You're not allowed to reach out to the client and call methods
on the client from the server in the form of events or calling methods on
objects passed to the server from the client. Well, technically, you're allowed
with DCOM, but it requires a "callback". To enable callbacks, the client
has to be capable of being a DCOM server for the server (because now the
client is the server and the server is now the client). Unless you have complete
control over the configuration of the clients, this isn't a trivial requirement.
You can use an asynchronous call and poll the server to monitor progress.
For example...
If you're using W2K on the clients, there's ways to make an asynch call to
the server (so I've read).
Or, you can use the old trick with a timer to make an asynch call (put the
call in a timer event so it won't block the rest of your application while
waiting for the method to return control). Turn the timer on when you want
to make your call.
Or, you could fake the whole thing by simply keeping statistics on how long
your methods take to execute (if they are predictable), make an asynch call,
and then update the progress bar accordingly.
If your processing is happening in a database, you can make a synchronous
(blocking) call to the server, but let it make an asynchronous call to the
database and return control to the client. You'll have to poll the database
to see how progress is going or use the statistical trick. There might be
a way to get the database to report on the percent complete for a given query
- not my area of experience.
Or, you could break your processing into a bunch of smaller steps and call
them sequentially from the client (major performance killer).
Sorry for the bad news.
Tom
"Jeff Aziz" <nf10@hotmail.com> wrote:
>
>Hi,
>
>I'm using ATL (VC++) to create a COM server. In order to see the progress
>of the execution, i will needs a progress bar.
>
>Is there any way to have a progress bar on the server side (VC++)that i
can
>get from the client side (using VB)?
>
>thanks
>
>Jeff Aziz
-
Re: Progress bar on COM
Ok, here is a very kludgy (sp?) to do this. I have only ever used it once
where the customer was VERY adamant about progress bars being accurate (that
ruled out using timers).
1. Construct your remote process to return a GUID to the calling
application.
2. Create a share on the network server that the remote component can write
to.
3. Map a network drive to this share from your client applications.
4. Once the remote component is instantiated, have it write a file to that
shared folder. The file name will be the GUID. the extension of this file
will be the percent completed of the process.
5. The client application will monitor this shared folder for changes, read
the filename, and use the extension as a percent to update a progress bar.
I KNOW this is quite nasty, and will invoke all kinds of issues with hard
drive access and network traffic, but one of my past clients insisted on
this. It beats the **** out of maintaining state just for a darn progress
bar.
"Jeff Aziz" <nf10@hotmail.com> wrote in message
news:38fc9b45$1@news.devx.com...
>
> Hi,
>
> I'm using ATL (VC++) to create a COM server. In order to see the progress
> of the execution, i will needs a progress bar.
>
> Is there any way to have a progress bar on the server side (VC++)that i
can
> get from the client side (using VB)?
>
> thanks
>
> Jeff Aziz
-
Re: Progress bar on COM
"Raymond R Cassick" <raycass@adelphia.net> wrote:
>Ok, here is a very kludgy (sp?) to do this. I have only ever used it once
>where the customer was VERY adamant about progress bars being accurate (that
>ruled out using timers).
>
>1. Construct your remote process to return a GUID to the calling
>application.
>
>2. Create a share on the network server that the remote component can write
>to.
>
>3. Map a network drive to this share from your client applications.
>
>4. Once the remote component is instantiated, have it write a file to that
>shared folder. The file name will be the GUID. the extension of this file
>will be the percent completed of the process.
>
>5. The client application will monitor this shared folder for changes,
read
>the filename, and use the extension as a percent to update a progress bar.
>
>I KNOW this is quite nasty, and will invoke all kinds of issues with hard
>drive access and network traffic, but one of my past clients insisted on
>this. It beats the **** out of maintaining state just for a darn progress
>bar.
>
>
>"Jeff Aziz" <nf10@hotmail.com> wrote in message
>news:38fc9b45$1@news.devx.com...
>>
>> Hi,
>>
>> I'm using ATL (VC++) to create a COM server. In order to see the progress
>> of the execution, i will needs a progress bar.
>>
>> Is there any way to have a progress bar on the server side (VC++)that
i
>can
>> get from the client side (using VB)?
>>
>> thanks
>>
>> Jeff Aziz
>
>
There is an alternative if you are willing to convert the client Vb app to
an out-of-prosess server [active-x exe]. If so, a progress bar control from
a form can be hooked to a publicly creatable vb class that I call PBarHook
(which is very simple and can even display a status text). This hook class
can then be passed to the server method/function as a generic object which
in turn can manipulate the progress bar control thru the object's properites.
This would also work with a DCOM client.
Client form only need to call the object's Initialize method before passing
the object to the server component.
Server needs to set the Max, Value and Status(optional) properties appropriately.
Heck, If u care, you can even implement a cancel from the client.
Client sets the Max value to 0. Server during it processing periodically
checks the max value for 0 and if so terminates
what ever it is doing.
The following is the PBarHook class in VB
'/***********************************/
Option Explicit
Private objPBar As ProgressBar
Private objStatus As TextBox
Friend Function Initialize(pobjPBar As Control, Optional _ pobjStatusText
As Control) As Boolean
On Error GoTo InitializeError
Set objPBar = pobjPBar
If Not IsMissing(pobjStatusText) Then
Set objStatus = pobjStatusText
End If
Initialize = True
InitializeError:
End Function
Public Property Get Max() As Long
On Error Resume Next
Max = objPBar.Max
DoEvents
End Property
Public Property Let Max(ByVal lMax As Long)
On Error Resume Next
objPBar.Max = lMax
DoEvents
End Property
Public Property Get Value() As Long
On Error Resume Next
Value = objPBar.Value
End Property
Public Property Let Value(ByVal lValue As Long)
On Error Resume Next
objPBar.Value = lValue
DoEvents
End Property
Public Property Let Status(ByVal sStatus As String)
On Error Resume Next
objStatus.Text = sStatus
DoEvents
End Property
Private Sub Class_Terminate()
Set objPBar = Nothing
Set objStatus = Nothing
End Sub
'/****************/
Hope it helps.
Srini