Skip to content

Commit 49623a6

Browse files
committed
NH-3807 - Use Task.Run instead of BeginInvoke
1 parent fcb00d2 commit 49623a6

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/NHibernate.Test/NHSpecificTest/NH2192/Fixture.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading;
4+
using System.Threading.Tasks;
45
using NUnit.Framework;
56

67
namespace NHibernate.Test.NHSpecificTest.NH2192
@@ -83,22 +84,22 @@ public void HqlIsThreadsafe_UsingPool()
8384
{
8485
List<Exception> exceptions = new List<Exception>();
8586
Func<int> result = FetchRowResults;
86-
List<IAsyncResult> results = new List<IAsyncResult>();
87+
List<Task<int>> results = new List<Task<int>>();
8788

88-
for (int i=0; i<_threadCount; i++)
89-
results.Add(result.BeginInvoke(null, null));
89+
for (int i = 0; i < _threadCount; i++)
90+
results.Add(Task.Run<int>(result));
9091

9192
results.ForEach(r =>
93+
{
94+
try
9295
{
93-
try
94-
{
95-
Assert.That(result.EndInvoke(r), Is.EqualTo(2));
96-
}
97-
catch (Exception e)
98-
{
99-
exceptions.Add(e);
100-
}
101-
});
96+
Assert.That(r.Result, Is.EqualTo(2));
97+
}
98+
catch (Exception e)
99+
{
100+
exceptions.Add(e);
101+
}
102+
});
102103

103104
if (exceptions.Count > 0)
104105
throw exceptions[0];

src/NHibernate.Test/NHSpecificTest/NH3050/Fixture.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Reflection;
55
using System.Threading;
6+
using System.Threading.Tasks;
67

78
using NHibernate.Engine.Query;
89
using NHibernate.Linq;
@@ -144,11 +145,11 @@ where personIds.Contains(person.Id)
144145
}
145146
};
146147

147-
var queryExecutorAsyncResult = queryExecutor.BeginInvoke(null, null);
148-
var cacheCleanerAsyncResult = cacheCleaner.BeginInvoke(null, null);
148+
var queryExecutorAsyncResult = Task.Run(queryExecutor);
149+
var cacheCleanerAsyncResult = Task.Run(cacheCleaner);
149150

150-
queryExecutor.EndInvoke(queryExecutorAsyncResult);
151-
cacheCleaner.EndInvoke(cacheCleanerAsyncResult);
151+
queryExecutorAsyncResult.Wait();
152+
cacheCleanerAsyncResult.Wait();
152153

153154
Assert.IsTrue(allLinqQueriesSucceeded);
154155
}
@@ -161,4 +162,4 @@ where personIds.Contains(person.Id)
161162
}
162163
}
163164
}
164-
}
165+
}

0 commit comments

Comments
 (0)