-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathThreadEventsExample.cs
More file actions
56 lines (45 loc) · 1.08 KB
/
Copy pathThreadEventsExample.cs
File metadata and controls
56 lines (45 loc) · 1.08 KB
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
using System;
using Amib.Threading;
namespace STPExamples
{
public class MyResource : IDisposable
{
// ...
public void DoIt()
{
//...
}
public void Dispose()
{
//...
}
}
public class ThreadEventsExample
{
public static void Main()
{
SmartThreadPool stp = new SmartThreadPool();
stp.OnThreadInitialization += OnInitialization;
stp.OnThreadTermination += OnTermination;
stp.QueueWorkItem(DoSomeWork);
}
[ThreadStatic]
private static MyResource _resource;
public static void OnInitialization()
{
// Initialize the resource
_resource = new MyResource();
}
private static object DoSomeWork(object state)
{
// Use the resouce
_resource.DoIt();
return null;
}
public static void OnTermination()
{
// Do resource cleanup
_resource.Dispose();
}
}
}