473,722 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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.StartCountin g

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCountin g

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.BeginInvok e(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(a r)

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(B yVal sender As
System.Object, ByVal e As System.EventArg s) 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.StartCountin g
Dim ar As IAsyncResult

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

'Let em run. Async works and illustrates

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

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(a r)
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 EnterpriseServi ces - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = l

Return l

End Function

End Class
<Synchronizatio n(Synchronizati onOption.Requir ed),
EventTrackingEn abled(True)> _

Public Class myComClass

Inherits ServicedCompone nt

Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = l

Return l

End Function

End Class

Public Module myModule

Public Delegate Function TedsHandler() As Long

End Module



Jul 21 '05 #1
8 1996
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(B yVal sender As
System.Objec t, ByVal e As System.EventArg s) Handles
Button2.Clic k

'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.StartCountin g

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCountin g

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.BeginInvok e(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(a r)

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(B yVal sender As
System.Objec t, ByVal e As System.EventArg s) Handles
Button1.Clic k

'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.StartCountin g
Dim ar As IAsyncResult

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

'Let em run. Async works and illustrates

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

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(a r)
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 EnterpriseServi ces - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = l

Return l

End Function

End Class
<Synchronizati on(Synchronizat ionOption.Requi red),
EventTrackingE nabled(True)> _

Public Class myComClass

Inherits ServicedCompone nt

Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = 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(B yVal sender As
System.Object , ByVal e As System.EventArg s) Handles
Button2.Cli ck

'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.StartCountin g

Dim ar As IAsyncResult

'Prepare the second bad boy.

Dim del2 As TedsHandler

del2 = AddressOf x2.StartCountin g

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.BeginInvok e(Nothing, Nothing)

'Any code here will also run async.

'Wait for them both to return.

Dim l1 As Long = del.EndInvoke(a r)

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(B yVal sender As
System.Object , ByVal e As System.EventArg s) Handles
Button1.Cli ck

'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.StartCountin g
Dim ar As IAsyncResult

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

'Let em run. Async works and illustrates

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

'Any code here will also run async.

'Wait for them both to return.
Dim l1 As Long = del.EndInvoke(a r)
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 EnterpriseServi ces - Works grate but has
'the sync problem with the Shared member.
Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = l

Return l

End Function

End Class
<Synchronizat ion(Synchroniza tionOption.Requ ired),
EventTracking Enabled(True)> _

Public Class myComClass

Inherits ServicedCompone nt

Private Shared mlModuleLevelCo unter As Long = 0

Public Function StartCounting() As Long

Dim l As Long = mlModuleLevelCo unter + 1

System.Threadin g.Thread.Curren tThread.Sleep(3 000)

mlModuleLevelCo unter = 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 runasynchronous ly 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 forunderstandin g 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
789
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 completed. How can I do this? If I were to just put a Thread.Sleep with some arbitrary number ( say 5 minutes ) would the asynch web services continue to process? Or would they
6
10451
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 anything. I have searched through the Internet and seems like the reason it hangs the browser it's because XMLHTTP limits you to two concurrent HTTP connections to each remote host; so if more than 2 concurrent connections strike the script...
0
2645
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 any method or component to wrote registry) After I used "InstallUtil" to registry Enterprise Library (those DLLs) to the deployment server, the application runs smoothly. Now I wonder why i need to registry those Enterprise Library DLLs into
9
328
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 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...
0
2088
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 successfully run most of the SampleApp features (Register,Feedback,Error report, version check) The only method I can not execute is the BuyNow example. I have tried leveraging the Sharewarestarterkit.com web service to rule out locality, to no avail.
0
1219
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 page with a search box on top & 2 web parts that display search results using web services. Currently, I am calling these web services synchronously (which takes a while).
0
2173
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 completed call back, but I have not been able to catch it and dispose of it. How can gracefully handle this exception?
2
1765
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 established and data is retrieved sucessfully. when the class is configured to run inside enterprise services, it fails without proper error description.
4
1500
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 these technologies, but from just looking at their feature set, I noticed that they don't exactly share the same features, for example ES offers services such as just-in-time activation and object pooling that I don't see in EL. I need to know if I...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9238
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...
0
9088
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...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
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
4502
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
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.