All Questions
Tagged with .net multithreading
6,244
questions
1
vote
2
answers
124
views
Dictionary is having duplicate keys
Can a Dictionary have duplicate keys? Or is there something else, I am missing?
Here is the code
Dictionary initialization is at class level.
StoredPoints.Keys
Count = 4
[0]: "SN6J1701_B"
[...
-1
votes
1
answer
84
views
Synchronize large csv file into DB with dotnet core
I want to develop a batch process in .NET Core to synchronize a CSV file containing 3 million lines. The process reads data from the file, updates existing items in the database, and creates new items ...
1
vote
2
answers
82
views
How does a race condition occur?
I have a single item pool implementation:
public class OneItemPool<T>
{
private T? _item;
private object _lockForChangeValue = new();
private object _lockForPostItem = new();
...
0
votes
0
answers
39
views
C#.Net IBM MQ Multi threaded application Connection Issue with Username and Password
When I connect to IBM MQ QueueManager using multi-threading, it does not connect all of the requests to MQ. Few connect and few fail. If I use thread count as 1 then all the request are connected. ...
2
votes
1
answer
78
views
Is there some known official rationalization of why Task.IAsyncResult.CompletedSynchronously always returns false
The most recent documentation forTask's explicit interface member implementation of IAsyncResult.CompletedSynchronously states the following:
true if the operation completed synchronously; otherwise, ...
-2
votes
1
answer
72
views
Difference between calling an async method, and wrapping the call in Task.Run
I am trying to write an async job which runs in the background. There are two ways of doing it-
[Test]
public async Task method1()
{
Task task = run();
await Task.WhenAll(task);
}
[Test]
...
0
votes
0
answers
67
views
Is a thread execution slower when it's running inside a dll instead of a .exe?
I have a Visual Studio 2022 project where I'm creating a C++ DLL. This DLL exposes a function to start threads.
Subsequently, I have a C# DLL, also in Visual Studio 2022, which acts as a wrapper. It ...
-1
votes
2
answers
64
views
Parallel Tasks - Run Parallel threads but dont wait for other Tasks to complete and get the latest data from database
I am using Task library for running multiple tasks parallelly, and I am using below code to wait for other tasks to complete.
Parallel.ForEach(DatafromDB,
item => { DownloadSSR(mediator, ...
1
vote
2
answers
98
views
Why thread safety is listed as a benefit of immutability?
I was reading about Records in C# and read that they are immutable. And thread safety is written as a benefit of immutability. How immutability provides thread safety? I tried a code sample claiming ...
2
votes
1
answer
97
views
Do Monitor.Pulse and Monitor.Wait enter kernel mode?
Monitor.Wait() and Monitor.Pulse() are supposed to be more performant than using EventWaitHandle derived classes such as ManualResetEvent per this source.
In terms of performance, calling Pulse takes ...
0
votes
1
answer
96
views
Difference between Debug and Release mode in Dotnet Application in a specific scenario
I was going through to reading asynchronous programming in .NET
There mention about debug and release mode of simple program using thread.
Consider following code:
internal class Program
{
static ...
0
votes
0
answers
75
views
How to improve the performance using Parallel.ForEachAsync
I have below code which will call couple of services and finally add the items to collection. I am using Parallel.ForEachAsync for fast performance for processing each id in request. But it's taking ...
0
votes
1
answer
65
views
Given a singleton class injected via DI, what happens when multiple threads hit the singleton method
I have a very basic question:
Say I have below class which is registered as singleton, and a method. What happens when Create() is hit by multiple threads? Do they all the threads get access to this ...
0
votes
1
answer
42
views
How to create a thread and pass (this) inside a member function of a managed class without using Lamda in c++
I am using windows winform and i have another ref class detector with Detector.h and Detector.cpp file.
In Detector.cpp file in the member function I want to create a thread which can update the ...
2
votes
1
answer
49
views
WAIT Throttling option does not seem to work for Channels
I am experimenting with System.Threading.Channels. And I noticed that throttling feature did not work as documented. Here is a very simple example:
public class Example
{
private readonly Channel&...