manishdubey
New member
- Joined
- Mar 31, 2017
- Messages
- 1
- Programming Experience
- 5-10
Hello Everyone,
I am working on a project which uses multithreading frequently. Currently I am stuck with the situation of deadlock. Below is the method which is accessed by the multiple threads and causing the deadlock:
Please let me know any solution by which I can make this method deadlock free. Thanks in advance.
I am working on a project which uses multithreading frequently. Currently I am stuck with the situation of deadlock. Below is the method which is accessed by the multiple threads and causing the deadlock:
C#:
[COLOR=#569cd6]public[/COLOR] [COLOR=#569cd6]bool[/COLOR] [COLOR=cyan]TryGetItem[/COLOR]([COLOR=lightblue]U[/COLOR] [COLOR=white]id[/COLOR], [COLOR=#569cd6]out[/COLOR] [COLOR=lightblue]T[/COLOR] [COLOR=white]item[/COLOR])
{
[COLOR=#569cd6]lock[/COLOR] ([COLOR=violet]lockingObject[/COLOR])
{
[COLOR=#569cd6]try[/COLOR]
{
[COLOR=#569cd6]return[/COLOR] [COLOR=violet]objectDictionary[/COLOR][COLOR=#b4b4b4].[/COLOR][COLOR=cyan]Find[/COLOR]([COLOR=white]id[/COLOR], [COLOR=#569cd6]out[/COLOR] [COLOR=white]item[/COLOR]);
}
[COLOR=#569cd6]catch[/COLOR] ([COLOR=lightblue]Exception[/COLOR])
{
[COLOR=white]item[/COLOR] [COLOR=#b4b4b4]=[/COLOR] [COLOR=#569cd6]null[/COLOR];
}
[COLOR=#569cd6]return[/COLOR] [COLOR=#569cd6]false[/COLOR];
}
}
Please let me know any solution by which I can make this method deadlock free. Thanks in advance.