-
Notifications
You must be signed in to change notification settings - Fork 0
/
UccPendingWorkItem.cs
76 lines (64 loc) · 1.7 KB
/
UccPendingWorkItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;
using System.Transactions;
using System.Threading;
namespace Netgao.Telephony.Workflow
{
public sealed class UccPendingWorkItem : IPendingWork
{
private Mutex mutex;
private bool result;
public UccPendingWorkItem(int ch)
{
mutex = OpenMutex(ch);
}
private static Mutex OpenMutex(int ch)
{
Mutex mutex = null;
string mutexName = "Mutex-" + ch.ToString();
try
{
mutex = Mutex.OpenExisting(mutexName);
}
catch
{
mutex = new Mutex(true, mutexName);
}
return mutex;
}
public bool Success
{
get { return result; }
set { result = value; }
}
public bool WaitForCommit()
{
return mutex.WaitOne();
}
public void Commit(Transaction transaction, ICollection items)
{
}
/**/
/// <summary>
/// SEts the outcome and signals completion.
/// </summary>
/// <param name="succeeded"></param>
/// <param name="items"></param>
public void Complete(bool succeeded, ICollection items)
{
Success = succeeded;
mutex.ReleaseMutex();
mutex.Close();
}
public bool MustCommit(ICollection items)
{
//always return true to avoid hang scenarios if not
//using persistence.
return true;
}
}
}