473,388 Members | 1,220 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,388 software developers and data experts.

Async and Enterprise Services

I'm using the BeginInvoke method of a delegate to invoke
a thread asynchronously and then use the EndInvoke to
retrieve the value. This works wonderfully until a
Serviced Component is added to the mix. When the
Serviced Component is invoked with BeginInvoke, the code
hangs for the duration of the call rather than running
async. Any ideas? Sample code below:

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click

'Purpose: Submit 2 components that share the same
' module-level variables. Attempt to
show

' that COM+ can solve synchronization
problems.

Dim x1 As New myComClass

Dim x2 As New myComClass

'Prepare the first bad boy.

Dim del As TedsHandler

del = AddressOf x1.StartCounting

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCounting

Dim ar2 As IAsyncResult

'Let em run. Each BeginInvoke takes

'3 seconds (due to the lag in the component).

'I expected these to run async. Why didn't they?

ar = del.BeginInvoke(Nothing, Nothing)

ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(ar)

Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)

Label2.Text = l2.ToString

x1.Dispose()

x1 = Nothing

x2.Dispose()

x2 = Nothing

End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click

'Purpose: Submit 2 components that share the same

' module-level variables. Attempt to
show

' syncronization problems.
Dim x1 As New myBadClass
Dim x2 As New myBadClass

'Prepare the first bad boy.
Dim del As TedsHandler
del = AddressOf x1.StartCounting
Dim ar As IAsyncResult

'Prepare the second bad boy.
Dim del2 As TedsHandler
del2 = AddressOf x2.StartCounting
Dim ar2 As IAsyncResult

'Let em run. Async works and illustrates

ar = del.BeginInvoke(Nothing, Nothing)
ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(ar)
Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)
Label2.Text = l2.ToString

x1 = Nothing
x2 = Nothing

End Sub

End Class
Public Class myBadClass

'Without EnterpriseServices - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class
<Synchronization(SynchronizationOption.Required) ,
EventTrackingEnabled(True)> _

Public Class myComClass

Inherits ServicedComponent

Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class

Public Module myModule

Public Delegate Function TedsHandler() As Long

End Module



Jul 21 '05 #1
8 1971
Hi,

After calling BeginInvoke use the following code to
execute any other functionality asynchronously

While Not ar.IsCompleted
'Logic for asynchronous operation
Wend

- Gopi
-----Original Message-----
I'm using the BeginInvoke method of a delegate to invoke
a thread asynchronously and then use the EndInvoke to
retrieve the value. This works wonderfully until a
Serviced Component is added to the mix. When the
Serviced Component is invoked with BeginInvoke, the code
hangs for the duration of the call rather than running
async. Any ideas? Sample code below:

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click

'Purpose: Submit 2 components that share the same ' module-level variables. Attempt to
show

' that COM+ can solve synchronization
problems.

Dim x1 As New myComClass

Dim x2 As New myComClass

'Prepare the first bad boy.

Dim del As TedsHandler

del = AddressOf x1.StartCounting

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCounting

Dim ar2 As IAsyncResult

'Let em run. Each BeginInvoke takes

'3 seconds (due to the lag in the component).

'I expected these to run async. Why didn't they?

ar = del.BeginInvoke(Nothing, Nothing)

ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(ar)

Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)

Label2.Text = l2.ToString

x1.Dispose()

x1 = Nothing

x2.Dispose()

x2 = Nothing

End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click

'Purpose: Submit 2 components that share the same
' module-level variables. Attempt to
show

' syncronization problems.
Dim x1 As New myBadClass
Dim x2 As New myBadClass

'Prepare the first bad boy.
Dim del As TedsHandler
del = AddressOf x1.StartCounting
Dim ar As IAsyncResult

'Prepare the second bad boy.
Dim del2 As TedsHandler
del2 = AddressOf x2.StartCounting
Dim ar2 As IAsyncResult

'Let em run. Async works and illustrates

ar = del.BeginInvoke(Nothing, Nothing)
ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(ar)
Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)
Label2.Text = l2.ToString

x1 = Nothing
x2 = Nothing

End Sub

End Class
Public Class myBadClass

'Without EnterpriseServices - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class
<Synchronization(SynchronizationOption.Required ),
EventTrackingEnabled(True)> _

Public Class myComClass

Inherits ServicedComponent

Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class

Public Module myModule

Public Delegate Function TedsHandler() As Long

End Module



.

Jul 21 '05 #2
My problem is that the BeginInvoke does not seem to be
running async. It seems to take the amount of time I put
the thread to sleep (3 secs in this case).
-----Original Message-----
Hi,

After calling BeginInvoke use the following code to
execute any other functionality asynchronously

While Not ar.IsCompleted
'Logic for asynchronous operation
Wend

- Gopi
-----Original Message-----
I'm using the BeginInvoke method of a delegate to invoke
a thread asynchronously and then use the EndInvoke to
retrieve the value. This works wonderfully until a
Serviced Component is added to the mix. When the
Serviced Component is invoked with BeginInvoke, the code
hangs for the duration of the call rather than running
async. Any ideas? Sample code below:

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click

'Purpose: Submit 2 components that share the

same
' module-level variables. Attempt to
show

' that COM+ can solve synchronization
problems.

Dim x1 As New myComClass

Dim x2 As New myComClass

'Prepare the first bad boy.

Dim del As TedsHandler

del = AddressOf x1.StartCounting

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCounting

Dim ar2 As IAsyncResult

'Let em run. Each BeginInvoke takes

'3 seconds (due to the lag in the component).

'I expected these to run async. Why didn't they?

ar = del.BeginInvoke(Nothing, Nothing)

ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(ar)

Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)

Label2.Text = l2.ToString

x1.Dispose()

x1 = Nothing

x2.Dispose()

x2 = Nothing

End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click

'Purpose: Submit 2 components that share the

same

' module-level variables. Attempt to
show

' syncronization problems.
Dim x1 As New myBadClass
Dim x2 As New myBadClass

'Prepare the first bad boy.
Dim del As TedsHandler
del = AddressOf x1.StartCounting
Dim ar As IAsyncResult

'Prepare the second bad boy.
Dim del2 As TedsHandler
del2 = AddressOf x2.StartCounting
Dim ar2 As IAsyncResult

'Let em run. Async works and illustrates

ar = del.BeginInvoke(Nothing, Nothing)
ar2 = del2.BeginInvoke(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(ar)
Label1.Text = l1.ToString

Dim l2 As Long = del2.EndInvoke(ar2)
Label2.Text = l2.ToString

x1 = Nothing
x2 = Nothing

End Sub

End Class
Public Class myBadClass

'Without EnterpriseServices - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class
<Synchronization(SynchronizationOption.Required) ,
EventTrackingEnabled(True)> _

Public Class myComClass

Inherits ServicedComponent

Private Shared mlModuleLevelCounter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCounter + 1

System.Threading.Thread.CurrentThread.Sleep(3000)

mlModuleLevelCounter = l

Return l

End Function

End Class

Public Module myModule

Public Delegate Function TedsHandler() As Long

End Module



.

.

Jul 21 '05 #3
Hi,

Thanks for your post. Do you mean that BeginInvoke does not run
asynchronously for a component? I suggest you to sleep in the component
internal processing to check whether it is execute synchronously or it just
require some overhead for the execution.

I look forward to your result.

Have a nice day! :-)

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4
The sample that was attached in the original post
included a sleep and, yes, the amount of time that
BeginInvoke waits directly corresponds to the amount of
time the component sleeps. BeginInvoke, therefore, is
not running async. Why?
-----Original Message-----
Hi,

Thanks for your post. Do you mean that BeginInvoke does not runasynchronously for a component? I suggest you to sleep in the componentinternal processing to check whether it is execute synchronously or it justrequire some overhead for the execution.

I look forward to your result.

Have a nice day! :-)

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #5
Hi,

Thanks for your information. I am creating a sample project to check it on
my side, and will update you with my information.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #6
Thanks! Any help is greatly appreciated!
-----Original Message-----
Hi,

Thanks for your information. I am creating a sample project to check it onmy side, and will update you with my information.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #7
Hi,

I reproduced the problem on my side, and found that Serviced Components
does not support in process asynchronous calls. If you have an serviced
component in-proc and call its method asynchronously (through a BeginInvoke
on a delegate on the method), the BeginInvoke actually executes as a
complete call (because all custom proxies do not really have a way to
distinguish sync vs async calls).

In .NET Framwork 1.0, it throws exceptions any time we detect that an async
delegate invocation (Begin/End-Invoke) is happening on a Non-RemotingProxy.
While in .NET Framework 1.1, we now just wrap async behaviour around the
calls to BeginInvoke and EndInvoke in a non-RemotingProxy case instead of
throwing an exception.

In addition, I believe the following article is very helpful for
understanding Enterprise Services in .NET:
http://www.gotdotnet.com/team/xmlentsvcs/espaper.aspx

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #8
Thanks for the info!
-----Original Message-----
Hi,

I reproduced the problem on my side, and found that Serviced Componentsdoes not support in process asynchronous calls. If you have an servicedcomponent in-proc and call its method asynchronously (through a BeginInvokeon a delegate on the method), the BeginInvoke actually executes as acomplete call (because all custom proxies do not really have a way todistinguish sync vs async calls).

In .NET Framwork 1.0, it throws exceptions any time we detect that an asyncdelegate invocation (Begin/End-Invoke) is happening on a Non-RemotingProxy.While in .NET Framework 1.1, we now just wrap async behaviour around thecalls to BeginInvoke and EndInvoke in a non- RemotingProxy case instead ofthrowing an exception.

In addition, I believe the following article is very helpful forunderstanding Enterprise Services in .NET:
http://www.gotdotnet.com/team/xmlentsvcs/espaper.aspx

Please feel free to let me know if you have any problems or concerns.
Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Jul 21 '05 #9

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

Similar topics

39
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have...
6
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing...
0
by: Benny Ng | last post by:
Hi,All, When i deploy Enterprise library with my application ,i used XCOPY to deploy it into my test server. But when application runs, shown some error related registry. (But actually I haven't...
9
by: Dave | last post by:
I'm using the BeginInvoke method of a delegate to invoke a thread asynchronously and then use the EndInvoke to retrieve the value. This works wonderfully until a Serviced Component is added to...
0
by: whizpop | last post by:
Hi, First of all, thanks for a great starter kit, now If I could just get it to work (fully). I am trying to compile and run the solution/services all on a local dev box. I am able to...
0
by: tg | last post by:
Hello, This is more of a design question. I am trying to understand how to use async web service invocation for asp.net 2.0 web parts with an Ajax style update / data rendering. I have a web...
0
by: koredump | last post by:
Hi all, I have a windows app that makes some asyc calls to my webservice (WSE 3.0 with MTOM). exception gets thrown in the client win app. I know this exception is caused on the async...
2
by: srinivasan.shanmugapillai | last post by:
Hi, I'm running a VB.NET windows applicatrion that is using the enterprise services transactions. While running this application without enterprise services support, a connection is...
4
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I was wondering whether the Enterprise Library replaces Enterprise Services as a framework for providing services for enterprise apps, or it supplements it. I know nothing of either of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.