Do

Merge lp:~psybers/do/thread into lp:do

Proposed by Robert Dyer
Status: Merged
Merged at revision: not available
Proposed branch: lp:~psybers/do/thread
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~psybers/do/thread
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve
Review via email: mp+7648@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Can you explain why we want this API change?

Revision history for this message
Robert Dyer (psybers) wrote :

> Can you explain why we want this API change?

The reason I developed this branch was due to my need in a plugin to have access to the created thread. I needed to be able to stop and/or join the thread created and was simply duplicating the code this API provides to get that functionality.

This code can be in the pipeline for when we have other ABI changes and pushed at that time. It is very low priority.

Revision history for this message
Alex Launi (alexlauni) wrote :

Looks fine to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform/src/Do.Platform/AbstractApplicationService.cs'
2--- Do.Platform/src/Do.Platform/AbstractApplicationService.cs 2009-01-17 22:48:10 +0000
3+++ Do.Platform/src/Do.Platform/AbstractApplicationService.cs 2009-06-18 19:52:32 +0000
4@@ -47,7 +47,10 @@
5 /// <param name="action">
6 /// A <see cref="Action"/> to run on a worker thread.
7 /// </param>
8- public abstract void RunOnThread (Action action);
9+ /// <returns>
10+ /// A reference to the created <see cref="Thread"/>.
11+ /// </returns>
12+ public abstract Thread RunOnThread (Action action);
13
14 /// <summary>
15 /// Run an action on a worker thread after a delay (ms).
16@@ -59,9 +62,12 @@
17 /// A <see cref="System.Int32"/> delay (in millseconds)
18 /// to wait before running the action.
19 /// </param>
20- public void RunOnThread (Action action, int delay)
21+ /// <returns>
22+ /// A reference to the created <see cref="Thread"/>.
23+ /// </returns>
24+ public Thread RunOnThread (Action action, int delay)
25 {
26- RunOnThread (action, new TimeSpan (0, 0, 0, 0, delay));
27+ return RunOnThread (action, new TimeSpan (0, 0, 0, 0, delay));
28 }
29
30 /// <summary>
31@@ -74,9 +80,12 @@
32 /// A <see cref="TimeSpan"/> delay to wait before running
33 /// the action.
34 /// </param>
35- public void RunOnThread (Action action, TimeSpan delay)
36+ /// <returns>
37+ /// A reference to the created <see cref="Thread"/>.
38+ /// </returns>
39+ public Thread RunOnThread (Action action, TimeSpan delay)
40 {
41- RunOnThread (() => {
42+ return RunOnThread (() => {
43 Thread.Sleep (delay);
44 action ();
45 });
46
47=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultApplicationService.cs'
48--- Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultApplicationService.cs 2009-01-17 22:35:46 +0000
49+++ Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultApplicationService.cs 2009-06-18 19:52:32 +0000
50@@ -20,6 +20,7 @@
51 using System;
52 using System.IO;
53 using System.Collections.Generic;
54+using System.Threading;
55
56 using Do.Universe;
57
58@@ -35,10 +36,11 @@
59 }
60 }
61
62- public override void RunOnThread (Action action)
63+ public override Thread RunOnThread (Action action)
64 {
65 Log<DefaultApplicationService>.Debug ("Cannot run action on a thread.");
66 action ();
67+ return null;
68 }
69
70 public override void RunOnMainThread (Action action)
71
72=== modified file 'Do/src/Do.Platform/ApplicationService.cs'
73--- Do/src/Do.Platform/ApplicationService.cs 2009-01-17 22:35:46 +0000
74+++ Do/src/Do.Platform/ApplicationService.cs 2009-06-18 19:52:32 +0000
75@@ -46,18 +46,23 @@
76 get { return items; }
77 }
78
79- public override void RunOnThread (Action action)
80+ public override Thread RunOnThread (Action action)
81 {
82 if (action == null) throw new ArgumentNullException ("action");
83
84- new Thread (() => {
85+ Thread newThread = new Thread (() => {
86 try {
87 action ();
88+ } catch (ThreadAbortException e) {
89 } catch (Exception e) {
90 Log.Error ("Error in RunOnThread: {0}", e.Message);
91 Log.Debug (e.StackTrace);
92 }
93- }).Start ();
94+ });
95+
96+ newThread.Start ();
97+
98+ return newThread;
99 }
100
101 public override void RunOnMainThread (Action action)