Friday, March 20, 2020

Multithreading - passing parameters

    When you need to write multithreading application, you might need to pass parameters to the method that is executed by another thread. Sometimes, assigining the value to a variable and access it from the method works but what if it's countless threads that access the same method. 

You can directly pass the values to the parameter. Look at the below code.


This is the method that needs to be executed by another thread. (Actually a loop of threads). This is how it can be done.


k.Key is the keyword and v is the url.

This way you can pass parameters and will not be effected to any thread.

Happy coding..


No comments:

Post a Comment