当前位置: 首页>>代码示例>>C#>>正文


C# System.Thread类代码示例

本文整理汇总了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);
     });
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:TargetArrayObject.cs

示例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] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:27,代码来源:ThreadTests.cs

示例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;
        }
开发者ID:DubeyAnkur,项目名称:Codility,代码行数:29,代码来源:Sulphur.cs

示例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] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:26,代码来源:CoreTests.cs

示例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
            }
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:32,代码来源:ThreadPoolTaskScheduler.cs

示例6: HasValue

 public bool HasValue(Thread thread)
 {
     return (bool) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return HasValue (target);
     });
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:TargetNullableObject.cs

示例7: GetValue

 public TargetObject GetValue(Thread thread)
 {
     return (TargetObject) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return Type.Value.Type.GetObject (target, Location);
     });
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:TargetEnumObject.cs

示例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();
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:29,代码来源:ExceptionWindow.cs

示例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]++;
                }
            }
        }
开发者ID:rvlietstra,项目名称:ROS.NET,代码行数:28,代码来源:XMLRPCCallWrapper.cs

示例10: GetObject

 public object GetObject(Thread thread)
 {
     return thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return DoGetObject (target);
     });
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:TargetFundamentalObject.cs

示例11: ExceptionEventArgs

			public ExceptionEventArgs(Thread thread, ExceptionRecord record)
			{
				Contract.Requires(thread != null);
				Contract.Requires(record != null);
				this.Thread = thread;
				this.Record = record;
			}
开发者ID:MrTrillian,项目名称:Asmuth,代码行数:7,代码来源:ProcessDebugger.Events.cs

示例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
        }
开发者ID:Maldercito,项目名称:geoworks,代码行数:31,代码来源:1455525034$Form1.cs

示例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;
        }
开发者ID:kdavie,项目名称:Yammer.NET-2.0,代码行数:27,代码来源:Factory.cs

示例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();
        }
开发者ID:giorgosrevis,项目名称:C-Homeworks,代码行数:26,代码来源:Program.cs

示例15: Print

 public string Print(Thread thread)
 {
     return (string) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess memory) {
             return Print (memory);
     });
 }
开发者ID:baulig,项目名称:debugger,代码行数:7,代码来源:TargetObject.cs


注:本文中的System.Thread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。