Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it is necessary to check whether multiple operation on a table take place in the same time. ex 20 query at time execute in one table multi threaded using timer function

e.g. test db-> in test db -> temporary table->in this table  I want multiple operation .insert ,update at same time (in timer function) multi threaded in c# window application.

What I have tried:

<pre>I don't know any idea please tell me how to possible .
thank you for advance
Posted
Updated 2-May-21 20:06pm

1 solution

That's not a question we can answer from that little - the whole subject of multithreaded access is a complex one, and depends on what you are doing, how you are doing it, and what objects you use.

The problem is that not all objects are what is called "Thread safe" - which means that if two threads try to use the same object at the same time unpredictable results can occur, from data being returned wrongly, through the app crashing, right up to the data being hopelessly corrupted.
And it's because what most people thing of as an "atomic operation" in that it is a single instruction isn't in practice:
C#
x = x + 1;
Is four operations: "Fetch the value of x", "Fetch the value of one", "Add them together", "Store the result to x" - so if two threads are accessing that single line of code together, they can be doing any of the four operations either at the same time (if they are on separate cores) or one can be "interrupted" at any point and the other runs (if they are on the same core) - either way, the result could be that x is incremented by one twice (as you'd expect), or once because one result was overwritten by the other.

That's a simple example: when you get to more complex structures than a basic integer it's gets to be orders of magnitude more complicated to work out what could be happening - hence "unpredictable results" may occur!

Threading is not (and never has been) a "magic bullet" that will make your code faster - it's a very complicated subject that needs long, hard thought before you ever go near code!
Start here: A gentle introduction to multithreading - Internal Pointers[^] and expect to have to read a whole load more before you begin designing a multithreaded app!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900