Thanks guys for all the support on this video. I have been meaning to make another tutorial about sounds and creating uncompressed .wav files. However I have been busy. So Hopefully in the next two-ish weeks.
@73h73373r3579 жыл бұрын
A thread is defined as the smallest sequence of instructions that can be managed independently by a scheduler. In other words, a thread is basically, the smallest block of a code of one single program that can be safely executed, then exited, then restarted without corrupting the program. In c# this would be equivalent to a method. Threading is simply the act of timesharing (either with multiple cores, or time sliced within an individual core) multiple threads, which can either be from the same process if functions can be completed in parallel, or from multiple different processes.
@garrettcolas11 жыл бұрын
Keep in mind things like hyper-threading simulate multiple cores. So an i3 processor only has 2 physical cores, but can hyper-thread on each to effectively have 4 cores.
@kentbrook25687 жыл бұрын
Nice demo, easy to understand even without a working sound card. Ignore these silly nit pickers that troll your work and do no work themselves... great stuff, please keep it up!
@spanout9 жыл бұрын
Great and simple demonstration that makes perfect sense!
@MauryaSandeep7 жыл бұрын
Awesome. It worked perfectly without any cross thread issues.....
@mandarinnu3 жыл бұрын
Thank you. A small suggestion: You could do some refactoring, i.e., refactor the thread() and threadb() methods.
@ProfFranciscoAraujo8 жыл бұрын
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace APP1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Thread th1; Thread th2; Random rdm; private void Form1_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; rdm = new Random(); } private void button1_Click(object sender, EventArgs e) { // var x = MessageBox.Show("Vermelho", "Mensagem"); th1 = new Thread(thread1); th1.Start(); } private void button2_Click(object sender, EventArgs e) { // var x = MessageBox.Show("Azul", "Mensagem"); th2 = new Thread(thread2); th2.Start(); } public void thread1() { for (int i = 0; 1 < 100; i++) { this.CreateGraphics().DrawRectangle(new Pen(Brushes.Red, 4), new Rectangle(rdm.Next(0, this.Width), rdm.Next(0, this.Height), 20, 20)); Thread.Sleep(100); } } public void thread2() { for (int i = 0; 1 < 100; i++) { this.CreateGraphics().DrawRectangle(new Pen(Brushes.Blue, 4), new Rectangle(rdm.Next(0, this.Width), rdm.Next(0, this.Height), 20, 20)); Thread.Sleep(100); } } private void Form1_Closed(object sender, EventArgs e) { th1.Abort("Fim th1"); th2.Abort("Fim th2"); Environment.Exit(0); } } }
@benjaminchiozalde34147 жыл бұрын
no mames te rifaste
@marcohundINV6 жыл бұрын
you misstyped the for loop .. u typed for (int i = 0; 1 < 100; i++) instead of for (int i = 0; i < 100; i++)
@ProfFranciscoAraujo8 жыл бұрын
Wow! The best example i'm found! Thanks Brandon!
@BrandonHilde1298 жыл бұрын
+Francisco Araújo thanks!
@pebito8 жыл бұрын
This tut is easy to understand, however you should not use variable names like "th" and "th1" not even when demonstrating. Giving "thread" as method name is a bad practice too. Not to mention in C# method names start with uppercase letters. Please follow the naming convention at all times!
@razshneider23755 жыл бұрын
i use a canvas for my drawing because of canvas.height but when i do canvas.refresh() to delete the drawings on a different thread it gives me an error System.InvalidOperationException: 'Cross-thread operation not valid: Control 'canvas' accessed from a thread other than the thread it was created on.' so should i stop using the canvas because you just did it on the form with the this.creategraphics but how do i refresh the form then, or get the height and width?
@killaurnext11 жыл бұрын
nicely done....not too complex and gets the point across
@Ak0tnik10 жыл бұрын
Thank you. This helped me a lot with a programming project (need to simulate how a dam gets its water drained on real time)
@RejhanKuch8 жыл бұрын
Nice write, thank you for sharing your video, it helped me a lot for some small project about threading I had.
@HawaiianDan12311 жыл бұрын
Very nicely done! Just what I needed.
@sandradebrauwer24014 жыл бұрын
I tried to run the graphics only in the main loading form but it didnot work, I used no button, perhaps I have to make a button
@jebclang94034 жыл бұрын
This exact example will only work with 2 CPU cores or more right? Otherwise, with 1 core, the 2 threads will only switch back and forth to complete their task in the same time it would take without multi threading.
@ogdencitizensclub10 жыл бұрын
Thank you very much, the explanation is both simple and complete, it helped a lot.
@bedennawulezi64487 жыл бұрын
Hello Brandon, Thank you for this tutoiral! I´m trying to read a sequence of values in array to my Arduino. I´m really not so good with programming. I problem is indeed how by just hitting a button, the arduino could read the values via serial port at a given interval. i.e reading the first row of data from dataTable. After making use of the values (eg. runs motors to position) then it waits for a particular period of time and read again the the 2nd row from the datatable. etc. Do u think u could help? I would be so grateful. Thank You! Bede
@thornphillips15657 жыл бұрын
Hey Brandon thanks for the tutorial. I am very new at programming and I was wondering, as I noticed you created a new thread method for each thread you were running, I couldn't help but to wonder if you could run multiple threads out of one method by maybe creating a new reference to it on each object. Seems like it would make for cleaner code.
@aleksandar532310 жыл бұрын
So if I want to set a parameter by the Return of a thread , but try to use this parameter before the thread is finished will it wait until it's done or crash? Only one way to find out :D
@donmohino44147 жыл бұрын
Thank you for this great tutorial. I am making a serial port data reader and i am having a problem: if i use the serialport.readline method in a thread(like you did in the video), an error shows up. This is what the error says: "Invalid inter-thread operation: The 'textBox1' control was accessed from a thread other than the one on which it was created". Any ideas the fix this?
@xarzu9 жыл бұрын
Good job. Easy to understand. And Kudos for debugging on the fly like that.
@jgmangala9 жыл бұрын
thanks..... with the the things go wrong... it really helps to understand core concept.
@fntasticHijack11 жыл бұрын
Ive tried to test my game, but when the computer thinks for a solution, my game was frozen. Can multi threads solve the problem? or you have another solution for that?
@carlosbvz10 жыл бұрын
I agree with other commets. Simple and complete. Thanks
@DanieboyTV9 жыл бұрын
Simply following the tutorial gave me an error: An unhandled exception of type 'System.NullReferenceException' occurred in Draw thread boxes.exe
@SB-hs4yn9 жыл бұрын
+DanieboyTV Check your code for grammatical errors and such.
@marcusrehn12 жыл бұрын
Threading like this is not hard, but I can never find a good video that includes the sharing of resources between different threads. Thats where it becomes harder.
@Kay-hx8xb8 жыл бұрын
If I have a function contains parameters like Method(a, b), so how can I initailize the instance of new thread?
@BrandonHilde1298 жыл бұрын
You can use a Parameterized ThreadStart to do that. Also you can use static variables that are created out side of the that thread. Hope this helps!
@Kay-hx8xb8 жыл бұрын
Ok, I created, initialized and ran it perfectly. And I think the way you recommended will work. Thank you.
@BrandonHilde1298 жыл бұрын
Awesome! glad it worked :)
@johnabraham92039 жыл бұрын
application should open with a splash screen that displays a disabled list of days of week for 10secs and proceed to next form
@chidhvilaskommineni14669 жыл бұрын
John Abraham done
@SaurabhSashank11 жыл бұрын
This is great stuff dear......
@leonardshin44698 жыл бұрын
Thank you for explaining beautifully what no one else including my AP comp Sci teacher couldn't explain. However, there is this weird caveat when i press the blue button three or more times. There occurs this error: :::::::An unhandled exception of type 'System.InvalidOperationException' occurred in System.Drawing.dll :::::::Additional information: Object is currently in use elsewhere. I was wondering if there was a way to prevent this from happening or at least why it''s throwing this error. Thank you and it'd be wonderful if you replied (Hint hint :) )
@maxratner61418 жыл бұрын
multiple things are calling the same DLL at the same time (in the separate threads), could be causing the conflict. Probably want to be checking in your code for these collisions. It's like trying to fit 5 cars into a 2 lane tunnel, I suppose?
@WoundedEgo11 жыл бұрын
Great job on this tutorial buddy, thanks.
@sergiopalazzi60336 жыл бұрын
Great tutorial. Good explanations! Thanks a lot.
@germandiez29747 жыл бұрын
i'm not making a videogame, but this really help me tahnks man!
@chrisjohnson72556 жыл бұрын
Cool stuff I'll probably need this soon.
@paulcox972810 жыл бұрын
good job with this, thanks, subscribed and liked
@sazzzz8783734789 жыл бұрын
Can you share this source of this tutorial ?
@lior1997712 жыл бұрын
thanks for the vid. can you to make me a tutorial about making sound effects for my games. thanks
@khuyenbuivan76588 жыл бұрын
Thank you. Great video
@BrandonHilde12911 жыл бұрын
That is true. however I try to keep my explanations simple. but thanks for the clarity.
@vincenguyen13569 жыл бұрын
I learn best with trial and error. Good tutorial Thanks
@zzvila11 жыл бұрын
How can I do this using Process
@kernelle411 жыл бұрын
thank you, you have earned a new sub
@standinonstilts11 жыл бұрын
Great video!
@zillabunny10 жыл бұрын
very nice!
@josemena6498 жыл бұрын
can you do pack man game in c# too ?? im a beginer and i lie to learn how to do it PLS just a symple code pls
@BrandonHilde1298 жыл бұрын
maybe. not sure right now.
@StansPreviouslyOwnedSoundtrack8 жыл бұрын
Brilliant, thank you!!
@indrajaya91578 жыл бұрын
ON YOUR CODE AND MY CODE WEWEWW WELL WELL WELL
@madvvasp9 жыл бұрын
Good tutorial, thank you! PS. Try to use GitHub to share the code (do not confuse with Pornhub :) ) Good luck!
@BrandonHilde1299 жыл бұрын
+Юрий Руд thanks dude but I think people learn better when they don't copy and paste code. So I prefer that people follow along.
@MegaMeno7 жыл бұрын
Brandon Hilde no, it's actually the other way around. That's why teachers give full examples so the learners can learn better, when the questions come the will know how to solve them because they know their logic.
@joacimjohnsson11 жыл бұрын
Hi, Great... I would be interested in a tutorial on how to move the boxes with the mouse. You dont have to go on from this tutorial, you could start simple with moving a box tipsNtricks... thanks Jo
@djdannyback34559 жыл бұрын
Você poderia me passar o código?
@BrandonHilde12912 жыл бұрын
I just put up a video about playing sound a few days ago... you should check it out
@garrettcolas11 жыл бұрын
Come on man, you can't just say programming for the console is worthless. It's very important for business/enterprise applications.
@khalilburno97139 жыл бұрын
NICE smart and short tip , thank you ,but the sound is too low i cant here you almost thank you thumbs up ;-)
@ivyliu618211 жыл бұрын
Very useful!
@4kills4827 жыл бұрын
Nice video but you kept repeating that multi threads will make your programm faster. This is only partially true. If you run the application on a single core cpu the cpu will process one thread at a time, then halt that first thread to execute the second one etc.. It will not process simultaneiously. Unless you are using multi core cpus threading won't lead to a performance increase. Programmers should use threading as often as possible where possible, in order to make use of multi core processors nowadays. A lot of programms are badly written by not distributing workload across multiple processing cores.