c# (Csharp) and .NET :- Multithreading and thread safe objects.

26
1



For more such videos visit
For more such videos subscribe

See our other Step by Step video series below :-
Learn C# Step by Step
Learn Design Pattern Step by Step:-
Learn Angular tutorial step by step
Learn MVC Core step by step :-
Learn Azure Step by Step :-
Learn SharePoint Step by Step in 8 hours:-
Python Tutorial for Beginners:-
Learn Data Science in 1 hour :-
Learn Power BI Step by Step:-
Learn MSBI Step by Step in 32 hours:-
Learn SQL Server Step by Step
Learn Tableau step by step :-

In this video we will try to implement thread safety in c# objects using lock keyword. When we talk about multithreading , concurrency can cause abnormal issues if the object is not thread safe. In this c# video we will first try to understand the concept of thread safety and then we will see how locking helps to implement thread safety.

We are also distributing a 100 page Ebook “.NET Interview Questions”. If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on questpond@questpond.com with the shared link and we will email you the PDF.

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

26 COMMENTS

  1. It is a great video for learning. i could not find linked video of this one. i would like to learn mutex, monitor and semaphore too..do you have video for that too?

  2. Your videos are clear and easy to understand. In fact your tutorials including this video helped me pass the technical interviews in one of the biggest investment bank in UK. Thanks a lot.

  3. excuse me, but wouldn't it make more sense to NOT declare the object as static? as per my understanding, both threads are using a static object, thus getting such error when calling because the values are the same across all the program (that's what static means)… Just asking because I noticed it at the very beggining and was wondering about it all along the duration of this video…

  4. Thanks for your video. But according to the documentation, you should avoid using "lock(this)" because it be dangerous.
    https://msdn.microsoft.com/en-us/library/ms173179.aspx

    Quote from the MSDN
    "Generally, it is best to avoid locking on a public type, or on object instances beyond the control of your application. For example, lock(this) can be problematic if the instance can be accessed publicly, because code beyond your control may lock on the object as well"

  5. hello sir…thanks to shear this video..but i still have some issue that i have four method on one button click… i want that the execution of all method will be at a time and if any method execution fail then it will be no execution….please sir help me at "programmer.rashid@gmail.com"

  6. Realy nice video, I have one question for you. In this example you open only two threads if you open multiple treads is there a chance for a deadlock? And if there is how you avoid it? For example if more than two threads want access of Num1 and Num2 to read or to write could resolve to a tread starving for ever?(Maybe not just three threads but more likely 10000 threads doing the same thing.

  7. Hello,
    I've written your code in the VS like.
     class Program
        {
            static Math math = new Math();
            static void Main(string[] args)
            {
                Thread t = new Thread(() => math.Divide(10));
                t.Start();
                math.Divide(20);
            }
        }

        public class Math
        {
            public int Num1;
            Random r = new Random();

            public void Divide(int y)
            {
                for (int i = 0; i < 2; i++)
                {
                    Num1 = r.Next(1, 2);
                    int result = y/Num1;
                    Console.Write(result);
                    Num1 = 0;
                }
            }
        }

    But It haven't get error as your video. Could you please help me to explain it?

  8. you shouldn't lock with "this", instead, you should lock with a private member object of that class, as the caller of the class should not have access on the object you are using to lock. Just sayin'

  9. If a part is locked so that only the current thread can execute, what do other threads do in the meantime?
    Do they wait for the lock to disappear or do they skip over the part or do they skip over the complete loop?

    Thanks!

  10. Thanks for the vids. They are very useful!
    One thing I noticed, because your mic is a bit cracky in the beginning: I turned on English subtitles and it makes the funniest of sentences based on your narrations! 😀

  11. dnfvideo I have a Question.
    This is the situation:
    I have Form with code that back's up files showin in a label th files that are being copied, and at the sametime picturebox with a Gif image is being show.
    How can I thread the Picturebox to show the gift mage without it to freeze when big file is being copied?
    Thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here