Friday, March 20, 2020
Multi-threading in C# With Tasks
Multi-threading in C# With Tasks The computer programming term thread is short forà threadà of execution, in which a processor follows a specified path through your code. The concept of following more than one thread at a time introduces the subject of multi-tasking and multi-threading. An application has one or more processes in it. Think of a process as a program running on your computer. Now each process has one or more threads. A game application might have a thread to load resources from disk, another to do AI, and another to run the game as a server. In .NET/Windows,à the operating system allocates processor time to a thread. Each thread keeps track of exception handlers and the priority at which it runs, and it has somewhere to save the thread context until it runs. Thread context is the information that the thread needs to resume. Multi-Tasking With Threads Threads take up a bit of memory and creating them takes a little time, so usually, you dont want to use many. Remember, they compete for processor time. If your computer has multiple CPUs, then Windows or .NET might run each thread on a different CPU, but if several threads run on the same CPU, then only one can be active at a time and switching threads takes time. The CPU runs a thread for a few million instructions, and then it switches to another thread. All of the CPU registers, current program execution point and stack have to be saved somewhere for the first thread and then restored from somewhere else for the next thread. Creating a Thread In the namespace System.Threading, youll find the thread type. The constructor threadà (ThreadStart) creates an instance of a thread. However, in recent C# code, its more likely to pass in a lambda expression that calls the method with any parameters. If youre unsure about lambda expressions, it might be worth checking out LINQ. Here is an example of a thread that is created and started: using System; using System.Threading;namespace ex1{class Program{public static void Write1(){Console.Write(1) ;Thread.Sleep(500) ;}static void Main(string[] args){var task new Thread(Write1) ;task.Start() ;for (var i 0; i 10; i){Console.Write(0) ;Console.Write (task.IsAlive ? A : D) ;Thread.Sleep(150) ;}Console.ReadKey() ;}}} All this example does is write 1 to the console. The main thread writes a 0 to the console 10 times, each time followed by an A or D depending on whether the other thread is still Alive or Dead. The other thread only runs once and writes a 1. After the half-second delay in the Write1() thread, the thread finishes, and the Task.IsAlive in the main loop now returns D. Thread Pool and Task Parallel Library Instead of creating your own thread, unless you really need to do it, make use of a Thread Pool. From .NET 4.0, we have access to the Task Parallel Library (TPL). Asà in the previous example, again we need a bit of LINQ, and yes, its all lambda expressions. Tasks uses the Thread Pool behind the scenesà but makeà better use of the threads depending on the number in use. The main object in the TPL is a Task. This is a class that represents an asynchronous operation. The commonest way to start things running is with the Task.Factory.StartNew as in: Task.Factory.StartNew(() DoSomething()); Where DoSomething() is the method that is run. Its possible to create a task and not have it run immediately. In that case, just use Task like this: var t new Task(() Console.WriteLine(Hello));...t.Start(); That doesnt start the thread until the .Start() is called. In the example below, are five tasks. using System;using System.Threading;using System.Threading.Tasks;namespace ex1{class Program{public static void Write1(int i){Console.Write(i) ;Thread.Sleep(50) ;}static void Main(string[] args){for (var i 0; i 5; i){var value i;var runningTask Task.Factory.StartNew(()Write1(value)) ;}Console.ReadKey() ;}}} Run that and youà get the digits 0 through 4 output in some random order such as 03214. Thats because the order of task execution is determined by .NET. You might be wondering why the var value i is needed. Try removing it and calling Write(i), and youll see something unexpected like 55555. Why is this? Its because the task shows the value of i at the time that the task is executed, not when the task was created. By creating a new variable each time in the loop, each of the five values is correctly stored and picked up.
Wednesday, March 4, 2020
Printable ACT Practice Tests PDFs 6 FREE Official Tests
Printable ACT Practice Tests PDFs 6 FREE Official Tests SAT / ACT Prep Online Guides and Tips No matter how you prep for the ACT- whether you have a tutor, take a class, or study by yourself- you must get access to official, printable ACT tests. These tests are released by ACT, Inc., and contain real questions given to actual students on previous test dates. Although all of these questions have been removed from circulation (meaning you won't ever see them on the real ACT), their quality is second to none when it comes to realistic ACT practice. In this post, I'll tell you where you can find all official, printable ACT practice tests with answer keys. I'll also give you key strategies to help you make big improvements on each practice test. 6 Free, Printable ACT Practice Tests Below are all six currently available PDFs for official ACT tests. Even though some practice tests are old (dating as far back as 2005), the format of the ACT hasn't changed much since then (except for the introduction of a redesigned Writing section in 2015), so you're basically still taking the same test from more than a decade ago. ACT Printable Practice Test 2018-2019 (Form 74FPRE) Test: p11-55. Answer key: p57-60. ACT Printable Practice Test 2015-16 (Form 72CPRE) Test: p11-55. Answer key: p57-62. ACT Printable Practice Test 2014-15 (Form 67C) Test: p11-51 (ignore the essay). Answer key: p56-62. ACT Printable Practice Test 2011-12 (Form 64E) Test: p13-56 (ignore the essay). Answer key: p60-65. ACT Printable Practice Test 2008-09 (Form 61C) Test: p13-55 (ignore the essay). Answer key: p60-64. ACT Printable Practice Test 2005-06 (Form 59F) Test: p13-55 (ignore the essay). Answer key: p60-65. Each test includes a full answer key so you can grade your test. Notice a few years missing? That's because ACT, Inc., often duplicates the same practice test in consecutive years. For example, the 2015-16 test is identical to the 2016-17 and 2017-18 tests. We've included the form ID for each test (in parentheses) so that you can check what's the same and what's different (the ID is located in the bottom-left corner of each page). Once you've downloaded a PDF practice test, I recommend printing it out and working through it on paper using official time limits (more on this in a moment). Note that these tests are not a cure-all for your ACT problems. To use them effectively, you'll need to learn what they do and don't do. You'll also need to make sure you're using ACT practice tests at an optimal frequency (in other words, don't take one too close to your ACT test date!). But how else can you utilize official practice tests in your ACT prep? 6 Strategies to Get the Most Out Of ACT Practice Tests When you set aside four hours for an ACT practice test, it's important to try to get the most out of your time and energy. Using our six critical tips below as you take your ACT tests can help you prepare more effectively for test day. #1: Print Out the Test and Work Through It on Paper You're going to take the actual ACT on paper (as opposed to a computer), so it's best to emulate this format by taking each practice test on paper, too. Do your scratch work directly in your "test book" (in other words, not on separate pieces of scratch paper- remember, you won't get any extra paper on test day, though you are allowed to take notes directly on your test!). If you're taking the Writing (essay) section, be sure to use the lined essay paper (included in each PDF above) to write out your essay by hand. #2: Keep Strict Timing on Every Section Many students struggle with time pressure on the ACT. Going over a section's time limit by just two minutes can make a noticeable difference in your score since you're essentially giving yourself the chance to answer two or three more questions. This is why it's so important to adhere to the official time limits. Not only will this help you get used to the test structure, but it'll also let you learn how to identify your weaknesses. Here are the official time limits on the ACT as well as approximately how long you should aim to spend per question on each section: ACT Section Time per Section Time per Question English 45 minutes 36 seconds Math 60 minutes 60 seconds Reading 35 minutes 52 seconds Science 35 minutes 52 seconds Writing (Optional) 40 minutes 40 minutes Last but not least, the ACT isn't without breaks, so make sure to rest during your test, too! #3: Take the Test in One Sitting, If Possible The ACT is a marathon: it lasts about four hours, and you have to take it on a Saturday morning. Thousands of students have told me how difficult it is to stay focused during the whole exam and how easy it is to make careless mistakes at the end of the test. Just like training for a marathon, you need to ensure you've got enough endurance to be able to succeed on the ACT. And the best way to do this is to take a practice test in one sitting- just as you will on test day. If there's no possible way for you to take an ACT test in one sitting (for example, maybe you're an athlete and have practice every day that completely wears you out), it's OK to split up the test over multiple days- just as long as you're obeying each section's time limit exactly. In the end, it's better to do some practice than none at all! #4: Review Your Answers and Mistakes The main point of taking ACT practice tests isn't just getting to do a lot of questions- it's being able to learn from your mistakes. For every test you take, review all of your mistakes as well as every question you got right. If you don't know why you missed a question, don't gloss over it! Doing this means you won't learn from your mistakes and will keep making them over and over again, thereby lowering your score. Ultimately, learn to prize study quality over quantity. It's better to take three ACT practice tests with detailed review instead of six practice tests with no review. #5: Take At Least 4 Practice Tests Before Test Day Based on my experience with thousands of students, I've found that taking four practice tests makes you extremely comfortable with the ACT in all respects: timing, endurance, and even stress. While you can definitely take more than four tests if you want, you'll need to balance this practice with some focused prep on your weaknesses so that you can make faster progress. #6: No Score Improvement? Supplement Your Practice Tests Some students are great at using practice tests to study by themselves- they'll see a mistake they made, instantly realize why they made it, and then avoid making it in the future. That said, most students need additional help with pinpointing their weaknesses and getting down key test-taking skills and strategies. Some of the best options for prep help include hiring a tutor, buying a comprehensive ACT prep book, and taking an online ACT prep course. Our dedicated guide can help you figure out which ACT prep method works best for you. What's Next? Ready to get a perfect ACT score? Read our famous guide on what it takes, written by an expert 36 scorer. If you're aiming for top scores on all four sections of the ACT, read our in-depth strategy guides on how to get a 36 on ACT English, ACT Math, ACT Reading, and ACT Science. Want to improve your ACT score by 4 points? Check out our best-in-class online ACT prep program. We guarantee your money back if you don't improve your ACT score by 4 points or more. Our program is entirely online, and it customizes your prep program to your strengths and weaknesses. We also have expert instructors who can grade every one of your practice ACT essays, giving feedback on how to improve your score. Check out our 5-day free trial:
Subscribe to:
Posts (Atom)