本文整理汇总了C#中Thread.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.Run方法的具体用法?C# Thread.Run怎么用?C# Thread.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread.Run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThreadWaitTillAllCompleteTest
public void ThreadWaitTillAllCompleteTest()
{
counter = 0;
Thread[] threads = new Thread[10];
for(int i = 0; i < threads.Length; i++) {
threads[i] = new Thread(() => {
Thread.SleepInSeconds(Random.Uint.LessThan(10));
counter++;
});
}
threads.Run();
Assert.IsTrue(counter == 10);
}
示例2: ThrottleIdTest
public void ThrottleIdTest()
{
DateTime start = DateTime.Now;
Thread[] threads = new Thread[10];
for(int i = 0; i < 10; i++) {
threads[i] = new Thread(() => {
throttleTest(counter++);
});
}
threads.Run();
TimeSpan span = DateTime.Now - start;
Assert.IsTrue(span > new TimeSpan(0, 0, 9));
Assert.IsTrue(span < new TimeSpan(0, 0, 90));
}
示例3: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var list = FindViewById<ListView>(Resource.Id.TestsList);
var selectButton = FindViewById<Button>(Resource.Id.SelectAllButton);
var deselectButton = FindViewById<Button>(Resource.Id.DeselectAllButton);
var runTestsButton = FindViewById<Button>(Resource.Id.RunTests);
var tests = GetAllTests();
MarkAllAs(tests, true);
list.Adapter = new TestListAdapter(this, tests);
selectButton.Click += (sender, args) =>
{
MarkAllAs(tests, true);
list.Adapter = new TestListAdapter(this, tests);
};
deselectButton.Click += (sender, args) =>
{
MarkAllAs(tests, false);
list.Adapter = new TestListAdapter(this, tests);
};
runTestsButton.Click += (sender, args) =>
{
SetContentView(Resource.Layout.Testing);
var selectedTests = tests.Where(item => item.Selected).ToList();
var thread = new Thread(() => RunTests(selectedTests));
thread.Run();
};
}
示例4: LogObserverThreadSafeTest
public void LogObserverThreadSafeTest()
{
ConfirmNotListening();
Log.RegisterListener(listenTest, Log.MessageType.ALL);
int loopCount = 3;
Thread[] threads = new Thread[5];
string message = "123.";
for(int i = 0; i < threads.Length; i++) {
threads[i] = new Thread(() => {
int p = 0;
p++;
for(int j = 0; j < loopCount; j++) {
Log.info(message);
}
});
}
threads.Run();
string repeatedMessage = "";
for(int i = 0; i < loopCount * threads.Length; i++) {
repeatedMessage += message;
}
Assert.AreEqual(repeatedMessage, listenTestMessages);
listenTestMessages = "";
Log.DeregisterListener(listenTest);
ConfirmNotListening();
}