示例#1
0
 public TargetObject GetElement(Thread thread, int[] indices)
 {
     return (TargetObject) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return GetElement (target, indices);
     });
 }
        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
0
        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
0
        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] );
        }
        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
0
 public bool HasValue(Thread thread)
 {
     return (bool) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return HasValue (target);
     });
 }
示例#7
0
 public TargetObject GetValue(Thread thread)
 {
     return (TargetObject) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return Type.Value.Type.GetObject (target, Location);
     });
 }
		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
0
        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
0
 public object GetObject(Thread thread)
 {
     return thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return DoGetObject (target);
     });
 }
示例#11
0
			public ExceptionEventArgs(Thread thread, ExceptionRecord record)
			{
				Contract.Requires(thread != null);
				Contract.Requires(record != null);
				this.Thread = thread;
				this.Record = record;
			}
示例#12
0
        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
0
        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
0
        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
0
 public string Print(Thread thread)
 {
     return (string) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess memory) {
             return Print (memory);
     });
 }
示例#16
0
 public TargetClassObject GetClassObject(Thread thread)
 {
     return (TargetClassObject) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             return GetClassObject (target);
     });
 }
 Thread IThreadService.Create(string subject, string body, Guid forumId, Guid authorId, int marks)
 {
     var forum = _repository.GetById<ForumModel>(forumId);
     var author = _repository.GetById<User>(authorId);
     var thread = new Thread(subject, body, forum, author, marks);
     _repository.Add(thread);
     return thread;
 }
示例#18
0
        private void btnArrays_Click(object sender, EventArgs e)
        {
            Thread t1 = new Thread(rellena);
            Thread t2 = new Thread(rellena);



        }
示例#19
0
 public TargetArrayBounds GetArrayBounds(Thread thread)
 {
     return (TargetArrayBounds) thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             GetArrayBounds (target);
             return bounds;
     });
 }
示例#20
0
 public void SetObject(Thread thread, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             Type.SetObject (target, Location, obj);
             return null;
     });
 }
示例#21
0
 public void Execute(MethodDefinition method)
 {
     ExecutionEngine engine = new ExecutionEngine();
     Thread thread = new Thread(engine);
     MethodState state = new MethodState(thread, method);
     thread.Methods.Push(state);
     thread.Execute();
 }
示例#22
0
 public void SetElement(Thread thread, int[] indices, TargetObject obj)
 {
     thread.ThreadServant.DoTargetAccess (
         delegate (TargetMemoryAccess target) {
             SetElement (target, indices, obj);
             return null;
     });
 }
示例#23
0
        public override void Execute( Command command, Thread thread, Scope scope )
        {
            char input = Console.ReadKey().KeyChar;

            if ( command.Identifier != "" )
                scope[ command.Identifier ] = TLObject.Convert( scope[ command.Identifier ].GetType(), new TLByt( (byte) input ) );

            thread.Advance();
        }
示例#24
0
        public override void Execute( Command command, Thread thread, Scope scope )
        {
            String input = Console.ReadLine();

            if ( command.Identifier != "" )
                scope[ command.Identifier ] = TLObject.Convert( scope[ command.Identifier ].GetType(), new TLStr( input ) );

            thread.Advance();
        }
示例#25
0
文件: b.cs 项目: xyandro/NeoEdit
		public CodeScanner(Action beep, int scanTimeout, int upcLotTimeout)
		{
			this.beep = beep;
			this.ScanTimeout = scanTimeout;
			this.UPCLotTimeout = upcLotTimeout;

			thread = new Thread(ReadScanner);
			thread.Start();
		}
		private static ThreadUsrSet GetParticipatingThreadUsrs(Thread thread)
		{
			Query tuQ = new Query();
			tuQ.ReturnCountOnly = true;
			tuQ.QueryCondition = new And(
				ThreadUsr.PrivateCanSeeQ,
				new Q(ThreadUsr.Columns.ThreadK, thread.K));
			ThreadUsrSet tus = new ThreadUsrSet(tuQ);
			return tus;
		}
示例#27
0
        public TargetAddress GetAddress(Thread thread)
        {
            if (!Location.HasAddress)
                throw new InvalidOperationException ();

            return (TargetAddress) thread.ThreadServant.DoTargetAccess (
                delegate (TargetMemoryAccess target) {
                    return Location.GetAddress (target);
            });
        }
示例#28
0
        public int ArchFStat64(Thread current, UserPtr buf)
        {
            var ret = IPCStubs.linux_sys_fstat64(current.Parent.helperPid, Fd);
            if (ret < 0)
                return ret;

            if (buf.Write(current, new Pointer(Globals.LinuxIPCBuffer.Location), GenericINode.SIZE_OF_STAT64) != 0)
                return -ErrorCode.EFAULT;

            return 0;
        }
示例#29
0
 /// <summary>
 /// Handle the Thread.ShowAndContinue method by writing the text to the console.
 /// </summary>
 /// <param name="thread">The Thread that called the Thread.ShowAndContinue method.</param>
 /// <param name="text">The text to show.</param>
 protected override void ShowAndContinue(Thread thread, String text)
 {
     if (text.Length == 0)
     {
         Write(thread, "", "Instruction finished");
     }
     else
     {
         Write(thread, text, "Instruction");
     }
 }
		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window.AddSubview (navigation.View);
			
			// this method initializes the main menu Dialog
			var startupThread = new Thread (Startup as ThreadStart);
			startupThread.Start ();
			
			window.MakeKeyAndVisible ();
			return true;
		}