本文整理汇总了C#中System.Thread类的典型用法代码示例。如果您正苦于以下问题:C# Thread类的具体用法?C# Thread怎么用?C# Thread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Thread类属于System命名空间,在下文中一共展示了Thread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElement
public TargetObject GetElement(Thread thread, int[] indices)
{
return (TargetObject) thread.ThreadServant.DoTargetAccess (
delegate (TargetMemoryAccess target) {
return GetElement (target, indices);
});
}
示例2: CallbackReturn
public void CallbackReturn()
{
var thread = new Thread();
var globals = new Table();
var func = Helpers.LoadFunc( "Thread/CallbackReturn.lua", globals );
int numCallbacks = 0;
globals[new LString( "callback" )] = (Callable)(l =>
{
Assert.AreEqual( 3, l.StackTop );
for( int i = 1; i <= 3; i++ )
l.Push( l[i].ToDouble() + i );
numCallbacks++;
return 3;
});
thread.Call( func, 0, 3 );
Assert.AreEqual( 2, numCallbacks );
Assert.AreEqual( 42, thread[1] );
Assert.AreEqual( 54, thread[2] );
Assert.AreEqual( 66, thread[3] );
}
示例3: solution
public int solution(int[] A, int[] B, int[] C)
{
// write your code in C# 6.0 with .NET 4.5 (Mono)
int N = A.Length;
Thread[] ths = new Thread[N];
for (int i = 0; i < N; i++)
{
Thread Curr = new Thread();
ths[i] = Curr;
Curr.Capacity = A[i] - B[i];
if (A[i] < B[i])
return i;
Thread prnt = null;
if (C[i] > -1)
prnt = ths[C[i]];
Curr.Parent = prnt;
while (Curr.Parent != null)
{
Curr = Curr.Parent;
Curr.Capacity -= B[i];
if (Curr.Capacity < 0)
return i;
}
}
return N;
}
示例4: RunTestScriptWithGlobals
private static void RunTestScriptWithGlobals( string script, Table globals, params Value[] expectedResults )
{
Libs.BaseLib.SetBaseMethods( globals );
Libs.MathLib.SetMathMethods( globals );
Libs.TableLib.SetTableMethods( globals );
Libs.StringLib.SetStringMethods( globals );
globals["print"] = (Callable)(l => 0);
globals["assert"] = (Callable)(l =>
{
if( !l[1].ToBool() )
Assert.Fail();
return 0;
});
var thread = new Thread();
var func = Helpers.LoadFunc( "lua-core/" + script, globals );
Function.Optimize( func );
thread.Call( func, 0, Thread.CallReturnAll );
Assert.AreEqual( expectedResults.Length, thread.StackTop );
for( int i = 0; i < expectedResults.Length; i++ )
Assert.AreEqual( expectedResults[i], thread[i + 1] );
}
示例5: QueueTask
protected internal override void QueueTask(Task task)
{
#if !FEATURE_PAL // PAL doesn't support eventing
if (TplEtwProvider.Log.IsEnabled(EventLevel.Verbose, ((EventKeywords)(-1))))
{
Task currentTask = Task.InternalCurrent;
Task creatingTask = task.m_parent;
TplEtwProvider.Log.TaskScheduled(this.Id, currentTask == null ? 0 : currentTask.Id,
task.Id, creatingTask == null? 0 : creatingTask.Id,
(int) task.Options);
}
#endif
if ((task.Options & TaskCreationOptions.LongRunning) != 0)
{
// Run LongRunning tasks on their own dedicated thread.
Thread thread = new Thread(s_longRunningThreadWork);
thread.IsBackground = true; // Keep this thread from blocking process shutdown
thread.Start(task);
}
else
{
#if PFX_LEGACY_3_5
ThreadPool.QueueUserWorkItem(s_taskExecuteWaitCallback, (object) task);
#else
// Normal handling for non-LongRunning tasks.
bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
#endif
}
}
示例6: HasValue
public bool HasValue(Thread thread)
{
return (bool) thread.ThreadServant.DoTargetAccess (
delegate (TargetMemoryAccess target) {
return HasValue (target);
});
}
示例7: GetValue
public TargetObject GetValue(Thread thread)
{
return (TargetObject) thread.ThreadServant.DoTargetAccess (
delegate (TargetMemoryAccess target) {
return Type.Value.Type.GetObject (target, Location);
});
}
示例8: ExceptionWindow
public ExceptionWindow(DebuggerService debuggerService, Thread thread, TargetEventArgs args)
{
this.debuggerService = debuggerService;
Glade.XML gxml = new Glade.XML("gui.glade", "exceptionWindow", null);
gxml.Autoconnect(this);
image.Pixbuf = Pixmaps.Exception.GetPixbuf();
if (args.Type == TargetEventType.UnhandledException) {
buttonContinue.Visible = false;
}
labelExceptionCaught.Text = (args.Type == TargetEventType.Exception ? "Exception" : "Unandled exception") + " has been caugth:";
StringBuilder sb = new StringBuilder();
StackFrame[] callstack;
try {
callstack = thread.GetBacktrace().Frames;
} catch {
return;
}
foreach(StackFrame frame in callstack) {
sb.Append(frame.ToString() + Environment.NewLine);
}
textviewCallstack.Buffer.Text = sb.ToString();
}
示例9: AddRef
private static void AddRef(IntPtr ptr)
{
#if REFDEBUGWrapper
if (refdumper == null)
{
refdumper = new Thread(dumprefs);
refdumper.IsBackground = true;
refdumper.Start();
}
#endif
lock (reflock)
{
if (!_refs.ContainsKey(ptr))
{
#if REFDEBUGWrapper
Console.WriteLine("Adding a new reference to: " + ptr + " (" + 0 + "==> " + 1 + ")");
#endif
_refs.Add(ptr, 1);
}
else
{
#if REFDEBUGWrapper
Console.WriteLine("Adding a new reference to: " + ptr + " (" + _refs[ptr] + "==> " + (_refs[ptr] + 1) + ")");
#endif
_refs[ptr]++;
}
}
}
示例10: GetObject
public object GetObject(Thread thread)
{
return thread.ThreadServant.DoTargetAccess (
delegate (TargetMemoryAccess target) {
return DoGetObject (target);
});
}
示例11: ExceptionEventArgs
public ExceptionEventArgs(Thread thread, ExceptionRecord record)
{
Contract.Requires(thread != null);
Contract.Requires(record != null);
this.Thread = thread;
this.Record = record;
}
示例12: btnConnect_Click
private void btnConnect_Click(object sender, EventArgs e)
{
Thread t = new Thread(handleClient);
#region pruebas hexa
string input = "Hello World!";
char[] values = input.ToCharArray();
foreach (char letter in values)
{
// Get the integral value of the character.
int value = Convert.ToInt32(letter);
// Convert the decimal value to a hexadecimal value in string form.
string hexOutput = String.Format("{0:X}", value);
Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
}
string hexValues = "48 65 6C 6C 6F 20 57 6F 72 6C 64 21";
string[] hexValuesSplit = hexValues.Split(' ');
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
int value = Convert.ToInt32(hex, 16);
// Get the character corresponding to the integral value.
string stringValue = Char.ConvertFromUtf32(value);
char charValue = (char)value;
Console.WriteLine("hexadecimal value = {0}, int value = {1}, char value = {2} or {3}",
hex, value, stringValue, charValue);
}
#endregion
}
示例13: Create
public static Feed.Base.Dynamic Create(FeedType type, int id)
{
object feed = null;
switch (type)
{
case FeedType.User:
feed = new User(id);
break;
case FeedType.Bot:
feed = new Bot(id);
break;
case FeedType.Favorites:
feed = new Favorites(id);
break;
case FeedType.Group:
feed = new Group(id);
break;
case FeedType.Tag:
feed = new Tag(id);
break;
case FeedType.Thread:
feed = new Thread(id);
break;
}
return feed as Feed.Base.Dynamic;
}
示例14: Main
static void Main(string[] args)
{
Random RandomNumber = new Random();
Thread thread1 = new Thread(new ThreadClass("ONE", RandomNumber).PrintInfo);
Thread thread2 = new Thread(new ThreadClass("TWO", RandomNumber).PrintInfo);
Thread thread3 = new Thread(new ThreadClass("THREE", RandomNumber).PrintInfo);
Thread thread4 = new Thread(new ThreadClass("FOUR", RandomNumber).PrintInfo);
Thread thread5 = new Thread(new ThreadClass("FIVE", RandomNumber).PrintInfo);
Thread thread6 = new Thread(new ThreadClass("SIX", RandomNumber).PrintInfo);
Thread thread7 = new Thread(new ThreadClass("SEVEN", RandomNumber).PrintInfo);
thread1.Start();
thread2.Start();
thread3.Start();
thread4.Start();
thread5.Start();
thread6.Start();
thread7.Start();
}
示例15: Print
public string Print(Thread thread)
{
return (string) thread.ThreadServant.DoTargetAccess (
delegate (TargetMemoryAccess memory) {
return Print (memory);
});
}