Skip to content

Commit bd33273

Browse files
committed
Removed installer project, will delivery releases via zip files. Added async helper file to help deal with .Result issues, added func to clean up watchers as they are eating up memory long term,
1 parent 2924f74 commit bd33273

File tree

11 files changed

+166
-350
lines changed

11 files changed

+166
-350
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace Resgrid.Providers.ApiClient
7+
{
8+
public static class AsyncHelpers
9+
{
10+
/// <summary>
11+
/// Execute's an async Task<T> method which has a void return value synchronously
12+
/// </summary>
13+
/// <param name="task">Task<T> method to execute</param>
14+
public static void RunSync(Func<Task> task)
15+
{
16+
var oldContext = SynchronizationContext.Current;
17+
var synch = new ExclusiveSynchronizationContext();
18+
SynchronizationContext.SetSynchronizationContext(synch);
19+
synch.Post(async _ =>
20+
{
21+
try
22+
{
23+
await task();
24+
}
25+
catch (Exception e)
26+
{
27+
synch.InnerException = e;
28+
throw;
29+
}
30+
finally
31+
{
32+
synch.EndMessageLoop();
33+
}
34+
}, null);
35+
synch.BeginMessageLoop();
36+
37+
SynchronizationContext.SetSynchronizationContext(oldContext);
38+
}
39+
40+
/// <summary>
41+
/// Execute's an async Task<T> method which has a T return type synchronously
42+
/// </summary>
43+
/// <typeparam name="T">Return Type</typeparam>
44+
/// <param name="task">Task<T> method to execute</param>
45+
/// <returns></returns>
46+
public static T RunSync<T>(Func<Task<T>> task)
47+
{
48+
var oldContext = SynchronizationContext.Current;
49+
var synch = new ExclusiveSynchronizationContext();
50+
SynchronizationContext.SetSynchronizationContext(synch);
51+
T ret = default(T);
52+
synch.Post(async _ =>
53+
{
54+
try
55+
{
56+
ret = await task();
57+
}
58+
catch (Exception e)
59+
{
60+
synch.InnerException = e;
61+
throw;
62+
}
63+
finally
64+
{
65+
synch.EndMessageLoop();
66+
}
67+
}, null);
68+
synch.BeginMessageLoop();
69+
SynchronizationContext.SetSynchronizationContext(oldContext);
70+
return ret;
71+
}
72+
73+
private class ExclusiveSynchronizationContext : SynchronizationContext
74+
{
75+
private bool done;
76+
public Exception InnerException { get; set; }
77+
readonly AutoResetEvent workItemsWaiting = new AutoResetEvent(false);
78+
readonly Queue<Tuple<SendOrPostCallback, object>> items =
79+
new Queue<Tuple<SendOrPostCallback, object>>();
80+
81+
public override void Send(SendOrPostCallback d, object state)
82+
{
83+
throw new NotSupportedException("We cannot send to our same thread");
84+
}
85+
86+
public override void Post(SendOrPostCallback d, object state)
87+
{
88+
lock (items)
89+
{
90+
items.Enqueue(Tuple.Create(d, state));
91+
}
92+
workItemsWaiting.Set();
93+
}
94+
95+
public void EndMessageLoop()
96+
{
97+
Post(_ => done = true, null);
98+
}
99+
100+
public void BeginMessageLoop()
101+
{
102+
while (!done)
103+
{
104+
Tuple<SendOrPostCallback, object> task = null;
105+
lock (items)
106+
{
107+
if (items.Count > 0)
108+
{
109+
task = items.Dequeue();
110+
}
111+
}
112+
if (task != null)
113+
{
114+
task.Item1(task.Item2);
115+
if (InnerException != null) // the method threw an exeption
116+
{
117+
throw new AggregateException("AsyncHelpers.Run method threw an exception.", InnerException);
118+
}
119+
}
120+
else
121+
{
122+
workItemsWaiting.WaitOne();
123+
}
124+
}
125+
}
126+
127+
public override SynchronizationContext CreateCopy()
128+
{
129+
return this;
130+
}
131+
}
132+
}
133+
}

Providers/Resgrid.Providers.ApiClient/Resgrid.Providers.ApiClient.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Reference Include="System.Xml" />
4747
</ItemGroup>
4848
<ItemGroup>
49+
<Compile Include="AsyncHelpers.cs" />
4950
<Compile Include="Properties\AssemblyInfo.cs" />
5051
<Compile Include="V3\CallsApi.cs" />
5152
<Compile Include="V3\Models\Call.cs" />

RelaySetup/Product.wxs

-154
This file was deleted.

RelaySetup/Product_en-us.wxl

-15
This file was deleted.

RelaySetup/RelaySetup.wax

-16
This file was deleted.

0 commit comments

Comments
 (0)