Hi.
The problem is a bit hard to explain.
I have a ServicedCompone nt method which runs a distributed transaction
consisting on a a MessageQueue reception and several database operations.
That ServicedCompone nt method is called from a pool of threads which get
blocked in the Receive method of the queue. At that moment there are as many
open transactions in the DTC as the number of threads in the pool. After 60
seconds of inactivity the transactions get cancelled by the DTC and the
threads get unblocked and everything starts again. My question is, how can I
achieve that a thread calls the ServicedCompone nt method (and thus starts a
new transaction) only when there is a message on the queue to be received?.
The problem is I get a lot of cancelled transactions because of timeouts of
the DTC, as I need a distributed transaction i cannot use the BeginReceive
method. If I use the BeginPeek method and instance the ServicedCompone nt on
the PeekCompleted, all the threads get unblocked and the same problem arises
again. Can anybody help me?
this is my code:
class Worker {
private int threadId;
public Worker (int threadId) {
this.threadId=t hreadId;
}
//doWork is the ThreadStart method
public void doWork() {
//ShippingProcess .endShippingPro cess is a static bool field
while (!ShippingProce ss.endShippingP rocess) {
try {
using (MessageHandler mh = new MessageHandler( )) {
mh.handleMessag e();
}
}
catch (Exception e) {
//Write EventLogEntry
}
}
}
}
[Transaction(Tra nsactionOption. Required)]
public class MessageHandler : ServicedCompone nt {
public MessageHandler( ) {
}
[AutoComplete()]
public void handleMessage() {
SHQM shippingMessage ;
STQM stockMessage;
using (MessageQueue queue = new MessageQueue(SH IPPING_QUEUE_ST RING)) {
try {
Type[] shipMessageType = {typeof(SHQM)};
queue.Formatter = new XmlMessageForma tter(shipMessag eType);
//ALL THE THREADS GET BLOCKED HERE
shippingMessage =
(SHQM)queue.Rec eive(MessageQue ueTransactionTy pe.Automatic).B ody;
}
catch (MessageQueueEx ception e) {
//Write EventLog
throw;
}
catch (Exception e) {
//Write EventLog
throw;
}
}
//DB operatios go here
}
}
}
Regards, Rodrigo. 2 2627
Hi Rodrigo,
You can use:
try
{
queue.Receive(T imeSpan.Zero, MessageQueueTra nsactionType.Au tomatic);
}
catch(MessageQu eueException e)
{
if( e.MessageQueueE rrorCode.IOTime out )
{
//Do what ever you want when there is no message in the queue.
}
}
Regards,
Dinh Duy Tran
[MCSD/CSDP]
"Rodrigo GarcĂ*a" wrote: Hi.
The problem is a bit hard to explain. I have a ServicedCompone nt method which runs a distributed transaction consisting on a a MessageQueue reception and several database operations. That ServicedCompone nt method is called from a pool of threads which get blocked in the Receive method of the queue. At that moment there are as many open transactions in the DTC as the number of threads in the pool. After 60 seconds of inactivity the transactions get cancelled by the DTC and the threads get unblocked and everything starts again. My question is, how can I achieve that a thread calls the ServicedCompone nt method (and thus starts a new transaction) only when there is a message on the queue to be received?.
The problem is I get a lot of cancelled transactions because of timeouts of the DTC, as I need a distributed transaction i cannot use the BeginReceive method. If I use the BeginPeek method and instance the ServicedCompone nt on the PeekCompleted, all the threads get unblocked and the same problem arises again. Can anybody help me?
this is my code:
class Worker { private int threadId;
public Worker (int threadId) { this.threadId=t hreadId; }
//doWork is the ThreadStart method public void doWork() { //ShippingProcess .endShippingPro cess is a static bool field while (!ShippingProce ss.endShippingP rocess) { try { using (MessageHandler mh = new MessageHandler( )) { mh.handleMessag e(); } } catch (Exception e) { //Write EventLogEntry } } } }
[Transaction(Tra nsactionOption. Required)] public class MessageHandler : ServicedCompone nt { public MessageHandler( ) { }
[AutoComplete()] public void handleMessage() { SHQM shippingMessage ; STQM stockMessage;
using (MessageQueue queue = new MessageQueue(SH IPPING_QUEUE_ST RING)) { try { Type[] shipMessageType = {typeof(SHQM)}; queue.Formatter = new XmlMessageForma tter(shipMessag eType); //ALL THE THREADS GET BLOCKED HERE shippingMessage = (SHQM)queue.Rec eive(MessageQue ueTransactionTy pe.Automatic).B ody; } catch (MessageQueueEx ception e) { //Write EventLog throw; } catch (Exception e) { //Write EventLog throw; } } //DB operatios go here } } }
Regards, Rodrigo.
Thanks for your advice.
If I do what you say, there will be more cancelled transactions.
The threads shouldn't create an instance of 'Distributed' if there aren't
messages on the queue. If you put a timeout of zero seconds, the threads will
be creating and destroying transactions if there aren't messages on the queue.
I tried with a BeginPeek call on the threads, but it didn't work as expected.
The goal is to get the threads blocked until there is a message but without
calling Receive or BeginReceive
Any more ideas would be helpful. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eirik Tryggeseth |
last post by:
During deployment of an application using distributed transactions managed
under COM+ on an Oracle 9i RAC database, we encounter situations where the
load balancing mechanisms in the RAC result in that the component context in
the distributed transaction (in our case two different COM components)
cannot hold onto the same ODBC connection. Or it may be that the database
session is changed dynamically for the ODBC connection, so that...
|
by: Richard Maher |
last post by:
Hi,
I am seeking the help of volunteers to test some software that I've
developed which facilitates distributed two-phase commit transactions,
encompassing any resource manager (e.g. SQL/Server or Oracle) controlled by
Microsoft's Distributed Transaction Coordinator in a Windows2000
environment, with any resource manager under the control of DECdtm (e.g. Rdb
(or Oracle via the XA Veneer)) in a VMS environment.
|
by: DotNetJunkies User |
last post by:
I am writing a distributed transaction code. My current scenario include a client database(Suppose client- having 4 main database) which can be installed anywhere which would connect to a public database placed at ISP datacentre(Suppose Server- having 2 database). this server database is added to client as linked server through vb.net interface. i have a transmission routine which transmitts the data from the client to Server and update client...
|
by: Jo Siffert |
last post by:
Hi all,
I would like to perform an
INSERT INTO LINKEDSVR.dbo.xyz.abc
SELECT ... FROM dbo.dfg
where LINKEDSVR is a linked server on another machine. Both servers are
running SQLServer 2000 and have the DTC running.
When I run this batch from QueryAnalyzer without explicitly using
|
by: Don Riesbeck Jr. |
last post by:
I have an C# EnterpriseService component that is part of an application I am
developing that is responsible for writing data to an SQL Server. (it reads
from a local DB (MSDE), then writes to a 'remote' DB (SQL Server 2k)...) On
some machines I get the following exception:
System.InvalidOperationException: An error occurred while enlisting in a
distributed transaction.
at...
| |
by: Rodrigo GarcĂa |
last post by:
Hi.
The problem is a bit hard to explain.
I have a ServicedComponent method which runs a distributed transaction
consisting on a a MessageQueue reception and several database operations.
That ServicedComponent method is called from a pool of threads which get
blocked in the Receive method of the queue. At that moment there are as many
open transactions in the DTC as the number of threads in the pool. After 60
seconds of inactivity the...
|
by: Dan Kelley |
last post by:
I have 2 services, ServiceA and ServiceB. Certain user driven functions
require ServiceA to perform some DB tasks, before sending a request to
ServiceB to perform some additional tasks. If ServiceB fails to execute the
request, I would like ServiceA to rollback its changes. ServiceA and ServiceB
are located on 2 different servers on the same network.
I am struggling to find resources that cover this scenario. most articles
that discuss...
|
by: Paul Rubin |
last post by:
Does anyone have an implementation of a distributed queue? I.e. I
have a long running computation f(x) and I'd like to be able to
evaluate it (for different values of x) on a bunch of different
computers simultaneously, the usual "worker thread" pattern except
distributed across a network. I guess this is pretty easy to write
with a centralized socket listener that dispatches requests through a
Queue to multiple threads on the same...
|
by: BLUE |
last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL?
Thanks,
Luigi.
|
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,...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |