473,848 Members | 1,801 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 2007
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
10465
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
2650
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
2099
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
1224
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
2176
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
1767
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
1507
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
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9738
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
10664
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...
1
10722
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
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
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3175
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.