本文整理汇总了C#中TaskScheduler.WaitFor方法的典型用法代码示例。如果您正苦于以下问题:C# TaskScheduler.WaitFor方法的具体用法?C# TaskScheduler.WaitFor怎么用?C# TaskScheduler.WaitFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskScheduler
的用法示例。
在下文中一共展示了TaskScheduler.WaitFor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClonePipelining
public void TestClonePipelining()
{
DoQuery("DROP TABLE IF EXISTS Test");
DoQuery("CREATE TABLE Test (value int)");
for (int i = 0; i < 10; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var q = qm.BuildQuery("SELECT * FROM Test");
var iter = q.Execute();
var iterF = scheduler.Start(iter.Fetch());
var fClone = qm.Clone();
Assert.IsFalse(fClone.Completed);
iter.Dispose();
iterF.Dispose();
scheduler.WaitFor(fClone);
using (var dupe = fClone.Result) {
q = dupe.BuildQuery("SELECT COUNT(value) FROM Test WHERE value = ?");
var f = q.ExecuteScalar(5);
var result = scheduler.WaitFor(f);
Assert.AreEqual(result, 1);
}
}
}
示例2: InsertBenchmark
public void InsertBenchmark (int warmupLength, int numInsertions, Func<IJobQueue> jobQueueFactory, Func<ConnectionWrapper, Query, int, IEnumerator<object>> insertTask) {
DoQuery("CREATE TABLE Test (A INTEGER NOT NULL, B INTEGER NOT NULL)");
var jobQueue = jobQueueFactory();
var wjq = jobQueue as WindowsMessageJobQueue;
using (var scheduler = new TaskScheduler(() => jobQueue))
using (var cw = new ConnectionWrapper(scheduler, Connection))
using (var query = cw.BuildQuery("INSERT INTO Test (A, B) VALUES (?, ?)")) {
scheduler.WaitFor(insertTask(cw, query, warmupLength));
DoQuery("DELETE FROM Test");
var e = insertTask(cw, query, numInsertions);
long timeStart = Time.Ticks;
scheduler.WaitFor(e);
long elapsed = Time.Ticks - timeStart;
var elapsedSeconds = (decimal)elapsed / Time.SecondInTicks;
Console.WriteLine(
"Inserted {0} row(s) in {1:00.000} second(s) at ~{2:000000.00} rows/sec.",
numInsertions, elapsedSeconds, numInsertions / elapsedSeconds
);
}
}
示例3: TestCloneConnectionWrapper
public void TestCloneConnectionWrapper()
{
DoQuery("DROP TABLE IF EXISTS Test");
DoQuery("CREATE TABLE Test (value int)");
for (int i = 0; i < 10; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var fClone = qm.Clone();
using (var dupe = scheduler.WaitFor(fClone)) {
var q = dupe.BuildQuery("SELECT COUNT(value) FROM Test WHERE value = ?");
var f = q.ExecuteScalar(5);
var result = scheduler.WaitFor(f);
Assert.AreEqual(result, 1);
}
}
}
示例4: TestTransactionPipelining
public void TestTransactionPipelining()
{
DoQuery("CREATE TEMPORARY TABLE Test (value int)");
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var getNumValues = qm.BuildQuery("SELECT COUNT(value) FROM test");
var addValue = qm.BuildQuery("INSERT INTO test (value) VALUES (?)");
var t = qm.CreateTransaction();
var fq = addValue.ExecuteNonQuery(1);
var fr = t.Rollback();
scheduler.WaitFor(Future.WaitForAll(t.Future, fq, fr));
var fgnv = getNumValues.ExecuteScalar();
long numValues = Convert.ToInt64(
scheduler.WaitFor(fgnv)
);
Assert.AreEqual(0, numValues);
t = qm.CreateTransaction();
fq = addValue.ExecuteNonQuery(1);
var fc = t.Commit();
scheduler.WaitFor(Future.WaitForAll(t.Future, fq, fc));
fgnv = getNumValues.ExecuteScalar();
numValues = Convert.ToInt64(
scheduler.WaitFor(fgnv)
);
Assert.AreEqual(1, numValues);
}
}
示例5: TestTransactionAutoRollback
public void TestTransactionAutoRollback()
{
DoQuery("CREATE TEMPORARY TABLE Test (value int)");
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var getNumValues = qm.BuildQuery("SELECT COUNT(value) FROM test");
var addValue = qm.BuildQuery("INSERT INTO test (value) VALUES (?)");
var f = scheduler.Start(CrashyTransactionTask(qm, addValue));
try {
scheduler.WaitFor(f);
Assert.Fail("Did not throw");
} catch (FutureException fe) {
Exception inner = fe.InnerException;
Assert.IsInstanceOfType(typeof(InvalidOperationException), inner);
}
var fgnv = getNumValues.ExecuteScalar();
long numValues = Convert.ToInt64(
scheduler.WaitFor(fgnv)
);
Assert.AreEqual(0, numValues);
}
}
示例6: TestQueryPipelining
public void TestQueryPipelining()
{
DoQuery("CREATE TEMPORARY TABLE Test (value int)");
for (int i = 0; i < 100; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var q1 = qm.BuildQuery("SELECT value FROM test");
var q2 = qm.BuildQuery("INSERT INTO test (value) VALUES (?)");
var iterator = q1.Execute();
var f1 = scheduler.Start(iterator.Fetch());
var f2 = q2.ExecuteNonQuery(200);
f1.RegisterOnComplete((f) => {
Assert.IsNull(f.Error);
Assert.AreEqual(f1, f);
Assert.AreEqual(true, f.Result);
Assert.IsTrue(f1.Completed);
Assert.IsFalse(f2.Completed);
});
f2.RegisterOnComplete((f) => {
Assert.IsNull(f.Error);
Assert.AreEqual(f2, f);
Assert.IsTrue(f1.Completed);
Assert.IsTrue(f2.Completed);
});
scheduler.WaitFor(f1);
scheduler.WaitFor(scheduler.Start(new Sleep(1.0)));
Assert.IsFalse(f2.Completed);
iterator.Dispose();
scheduler.WaitFor(f2);
}
}
示例7: TestQueryParameters
public void TestQueryParameters()
{
using (var scheduler = new TaskScheduler())
using (var wrapper = new ConnectionWrapper(scheduler, Connection)) {
scheduler.WaitFor(wrapper.ExecuteSQL("CREATE TEMPORARY TABLE Test (a INTEGER, b VARIANT)"));
using (var q = wrapper.BuildQuery("INSERT INTO Test (a, b) VALUES (?, ?)")) {
q.Parameters[1].DbType = DbType.Object;
Assert.AreEqual(DbType.Object, q.Parameters[1].DbType);
}
}
}
示例8: TestDbTaskIterator
public void TestDbTaskIterator()
{
DoQuery("CREATE TEMPORARY TABLE Test (value int)");
for (int i = 0; i < 100; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var q = qm.BuildQuery("SELECT value FROM Test WHERE value = ?");
using (var iterator = q.Execute(5)) {
scheduler.WaitFor(iterator.Fetch());
using (var e = iterator.CurrentItems) {
Assert.IsTrue(e.MoveNext());
Assert.AreEqual(e.Current.GetInt32(0), 5);
}
}
}
}
示例9: TestConnectionWrapper
public void TestConnectionWrapper()
{
DoQuery("CREATE TEMPORARY TABLE Test (value int)");
for (int i = 0; i < 100; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var q = qm.BuildQuery("SELECT COUNT(value) FROM Test WHERE value = ?");
var f = q.ExecuteScalar(5);
var result = scheduler.WaitFor(f);
Assert.AreEqual(result, 1);
q = qm.BuildQuery("SELECT @p0 - @p1");
f = q.ExecuteScalar(2, 3);
result = scheduler.WaitFor(f);
Assert.AreEqual(result, -1);
f = q.ExecuteScalar(new NamedParam { N = "p0", V = 4 }, new NamedParam { N = "p1", V = 3 });
result = scheduler.WaitFor(f);
Assert.AreEqual(result, 1);
f = q.ExecuteScalar(5, new NamedParam { N = "p1", V = 3 });
result = scheduler.WaitFor(f);
Assert.AreEqual(result, 2);
q = qm.BuildQuery("SELECT @[email protected]");
f = q.ExecuteScalar(new NamedParam { N = "parm1", V = 1 }, new NamedParam { N = "parm2", V = 2 });
result = scheduler.WaitFor(f);
Assert.AreEqual(result, -1);
}
}
示例10: TestGetResultAsObject
public void TestGetResultAsObject()
{
DoQuery("DROP TABLE IF EXISTS Test");
DoQuery("CREATE TABLE Test (value int)");
for (int i = 0; i < 10; i++)
DoQuery(String.Format("INSERT INTO Test (value) VALUES ({0})", i));
using (var scheduler = new TaskScheduler())
using (var qm = new ConnectionWrapper(scheduler, Connection)) {
var q = qm.BuildQuery("SELECT * FROM Test");
var f = q.ExecuteArray<object>();
Assert.IsFalse(f.Completed);
var seq = scheduler.WaitFor(f);
Assert.AreEqual(
new object[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, seq
);
}
}