2744a3bf95a288f8a35994b5180471b08fd37e1d
[mono.git] / mcs / class / referencesource / System.Workflow.Runtime / ExecutorLocksHeldException.cs
1 // ****************************************************************************
2 // Copyright (C) 2000-2001 Microsoft Corporation.  All rights reserved.
3 //
4 // CONTENTS
5 //     Workflow Base exception class
6 // 
7 // DESCRIPTION
8 //     Base class for WINOE Runtime engine exception
9 //
10 // REVISIONS
11 // Date          Ver     By           Remarks
12 // ~~~~~~~~~~    ~~~     ~~~~~~~~     ~~~~~~~~~~~~~~
13 // 03/08/01      1.0     Microsoft       Created.
14 // ****************************************************************************
15 using System;
16 using System.Runtime.Serialization;
17 using System.Security.Permissions;
18 using System.Collections.Generic;
19 using System.Globalization;
20 using System.Threading;
21 using System.Workflow;
22 using System.Workflow.Runtime;
23 using System.Workflow.ComponentModel;
24
25 namespace System.Workflow.Runtime
26 {
27     /*
28      * The Unload() method has been changed so that
29      * any Unload requests made while in the middle of an atomic
30      * transaction wait for the atomic transaction to complete.
31      * This makes use of an ManualResetEvent. Unload() waits on the event:
32      *      theEvent.WaitOne()
33      * But waiting with the executor and scheduler locks held
34      * will block everything else.
35      * 
36      * The solution is to have a custom internal exception class that has the
37      * ManualResetEvent as an internal property. If Unload() finds itself in the middle
38      * of an atomic transaction, it throws the Exception. The Exception is propogated upwards
39      * until we reach the method that was the first to grab the executor lock. 
40      *
41      * We then drop that lock and wait on the event handle. As soon as the handle is
42      * Set() by DisposeTransaction(), we grab the executor lock and do everything all over.
43      */
44
45     internal class ExecutorLocksHeldException : Exception
46     {
47         private ManualResetEvent handle;
48
49         public ExecutorLocksHeldException(ManualResetEvent handle)
50         {
51             this.handle = handle;
52         }
53
54         internal ManualResetEvent Handle
55         {
56             get
57             {
58                 return handle;
59             }
60         }
61     }
62 }