4 |
|
using System.Text; |
5 |
|
using libxmltv.Interfaces; |
6 |
|
using System.ComponentModel; |
7 |
+ |
using System.Windows.Forms; |
8 |
+ |
using System.Threading; |
9 |
|
|
10 |
|
namespace libxmltv.Core |
11 |
|
{ |
12 |
|
[Serializable] |
13 |
< |
internal class XMLTVRuntimeInstance : MarshalByRefObject, IXMLTVRuntimeInstance, ISerializer<XMLTVRuntimeInstance> |
13 |
> |
internal class XMLTVRuntimeInstance : MarshalByRefObject, IXMLTVRuntimeInstance, ISerializer<XMLTVRuntimeInstance>, IGetCreatedInstanceEvent, ISetCreatedInstanceEvent, IDestroyInstance |
14 |
|
{ |
15 |
< |
public XMLTVRuntimeInstance(string xmlfile) { CreateInstance(xmlfile); } |
15 |
> |
Thread worker; |
16 |
> |
public XMLTVRuntimeInstance(string xmlfile) |
17 |
> |
{ |
18 |
> |
worker = new Thread(new ParameterizedThreadStart(CreateInstance)); |
19 |
> |
//CreateInstance(xmlfile); |
20 |
> |
worker.Start(xmlfile); |
21 |
> |
} |
22 |
|
//public XMLTVRuntimeInstance(string xmlfile) : this(xmlfile, null) { } |
23 |
|
//public XMLTVRuntimeInstance(string xmlfile, EventHandler<CancelEventArgs> t) { CreateInstance(xmlfile,t); } |
24 |
< |
private void CreateInstance(string xmlfile) |
25 |
< |
{ |
24 |
> |
private void CreateInstance(object xmlfile) |
25 |
> |
{ |
26 |
|
//CancelEvent = t; |
27 |
< |
using (XMLTVInstance instance = new XMLTVInstance(xmlfile, this)) |
27 |
> |
using (XMLTVInstance instance = new XMLTVInstance(xmlfile.ToString(), this)) |
28 |
|
{ |
29 |
+ |
if (OnInstanceCreated != null) |
30 |
+ |
{ |
31 |
+ |
OnInstanceCreated.Invoke(this,new EventArgs()); |
32 |
+ |
} |
33 |
|
} |
34 |
|
} |
35 |
|
|
45 |
|
public Dictionary<int, IXMLTVProgram> Programs { get; set; } |
46 |
|
#endregion |
47 |
|
|
48 |
+ |
public EventHandler<EventArgs> OnInstanceCreated { get; set; } |
49 |
+ |
public EventHandler<EventArgs> GetOnInstanceCreated() { return OnInstanceCreated; } |
50 |
+ |
public void SetOnInstanceCreated(EventHandler<EventArgs> event_instance) { OnInstanceCreated = event_instance; } |
51 |
+ |
|
52 |
|
public IXMLTVSerializer<XMLTVRuntimeInstance> Serializer |
53 |
|
{ |
54 |
|
get |
59 |
|
return new XMLTVSerializer<XMLTVRuntimeInstance>(this); |
60 |
|
} |
61 |
|
} |
62 |
< |
//public void Dispose() |
47 |
< |
//{ |
48 |
< |
// IsDisposing = true; |
49 |
< |
// //throw new NotImplementedException(); |
50 |
< |
//} |
51 |
< |
//public bool IsDisposing { get; private set; } |
52 |
< |
|
53 |
< |
|
54 |
< |
//private event EventHandler<CancelEventArgs> CancelEvent = null; |
55 |
< |
|
56 |
< |
public bool IsAborting |
62 |
> |
public void DestroyInstance() |
63 |
|
{ |
64 |
< |
get |
64 |
> |
xmltv_logger.Log.Debug.WriteLine("Destoying Instance of: '{0}'", this.GetType().Name); |
65 |
> |
this.IsAborting = true; |
66 |
> |
if (worker == null) |
67 |
> |
{ |
68 |
> |
xmltv_logger.Log.Debug.WriteLine("Unable to destroy instance of: '{0}' - worker thread is null", this.GetType().Name); |
69 |
> |
return; |
70 |
> |
} |
71 |
> |
else |
72 |
|
{ |
73 |
< |
//if (CancelEvent != null) |
74 |
< |
//{ |
75 |
< |
// CancelEventArgs e = new CancelEventArgs(); |
76 |
< |
// CancelEvent.Invoke(this, e); |
77 |
< |
// if (e.Cancel) |
78 |
< |
// { |
79 |
< |
// xmltv_logger.Log.Verbose.Debug.WriteLine("Detected Instance abort event..."); |
80 |
< |
// } |
81 |
< |
// return e.Cancel; |
82 |
< |
//} |
83 |
< |
//return false; |
84 |
< |
return false; |
73 |
> |
if (worker.IsAlive) |
74 |
> |
{ |
75 |
> |
xmltv_logger.Log.Verbose.Debug.WriteLine("Requesting Instance to Abort..."); |
76 |
> |
while (worker.IsAlive) |
77 |
> |
{ |
78 |
> |
worker.Abort(); |
79 |
> |
Application.DoEvents(); |
80 |
> |
} |
81 |
> |
} |
82 |
> |
else |
83 |
> |
{ |
84 |
> |
xmltv_logger.Log.Debug.WriteLine("Instance of: '{0}'- already destroyed.", this.GetType().Name); |
85 |
> |
} |
86 |
|
} |
87 |
|
} |
88 |
< |
|
89 |
< |
|
88 |
> |
public bool IsAborting |
89 |
> |
{ |
90 |
> |
get; |
91 |
> |
private set; |
92 |
> |
} |
93 |
|
} |
94 |
|
|
95 |
|
internal class XMLTVInstance : IDisposable |