TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Zoran Markovic
NA
1
0
Catching exception in TransactionScope bug - exception never caught
Oct 6 2011 2:43 AM
I modified ImperativeTransactionSample of WF samples from WF_WCF_Samples and created situation when application execution is blocked. Here is code sample where Console.WriteLine("Stop") line is never executed:
using System;
using System.Activities;
using System.Activities.Statements;
using System.Transactions;
namespace Microsoft.Samples.ImperativeTransactionSample
{
sealed class Program
{
static void Main()
{
Console.WriteLine("Start");
try
{
using (System.Transactions.TransactionScope txScope = new System.Transactions.TransactionScope())
{
new WorkflowInvoker(BuildWF()).Invoke();
txScope.Complete();
};
}
catch (Exception ex)
{
Console.WriteLine("Exception : " + ex.Message);
}
Console.WriteLine("Stop");
Console.ReadLine();
}
static Activity BuildWF()
{
return new Sequence
{
Activities =
{
new TestActivity(),
new System.Activities.Statements.TransactionScope
{
Body = new Sequence
{
Activities =
{
new WriteLine { Text = "Hello" }
}
},
},
}
};
}
class TestActivity : NativeActivity
{
protected override void Execute(NativeActivityContext context)
{
using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
{
throw new Exception("Test");
}
}
}
}
}
The strange thing is that if I remove creation of TransactionScope activity inside workflow in BuildWF method everything works fine. What's the problem here and how I can avoid this situation?
static Activity BuildWF()
{
return new Sequence
{
Activities =
{
new TestActivity(),
//new System.Activities.Statements.TransactionScope
//{
// Body = new Sequence
// {
// Activities =
// {
// new WriteLine { Text = "Hello" }
// }
// },
//},
}
};
}
Reply
Answers (
1
)
Sequence in Worflow
Arguments in Workflow