當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。