|
Yeah, right, typo.
But this is not the point of the question!
|
|
|
|
|
Hi,
RollBack method; Roll back whatever changes have been made to the database.
Following example I didn't use Commit(), what will RollBack() do?
What exactly did transaction.Rollback() do?
using (var context = new AppDbContext())
{
using (var transaction = context.Database.BeginTransaction())
{
try
{
var myObjectOne = new MyObjectOne() { Name = "Book" };
context.MyObjectOnes.Add(myObjectOne);
context.SaveChanges();
var myVal = myObjectOne.Id * 3.14;
var myObjectTwo = new MyObjectTwo() { Name = "Notebook", Price = 100, ReferenceId = myVal };
context.MyObjectTwos.Add(myObjectTwo);
context.SaveChanges();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
}
}
}
thanks...
|
|
|
|
|
|
Thanks for the answer @Richard-MacCutchan
I read the article, but I didn't get the exact answer to my question. The EF Core working structure is different. Each process is primarily tracked on the memory.
Makes my question a little clearer. What is the difference in effect between the two codes below?
FIRST CODE:
using (var context = new AppDbContext())
{
using (var transaction = context.Database.BeginTransaction())
{
try
{
var myObjectOne = new MyObjectOne() { Name = "Book" };
context.MyObjectOnes.Add(myObjectOne);
context.SaveChanges();
var myVal = myObjectOne.Id * 3.14;
var myObjectTwo = new MyObjectTwo() { Name = "Notebook", Price = 100, ReferenceId = myVal };
context.MyObjectTwos.Add(myObjectTwo);
context.SaveChanges();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
}
}
}
SECOND CODE:
using (var context = new AppDbContext())
{
using (var transaction = context.Database.BeginTransaction())
{
try
{
var myObjectOne = new MyObjectOne() { Name = "Book" };
context.MyObjectOnes.Add(myObjectOne);
context.SaveChanges();
var myVal = myObjectOne.Id * 3.14;
var myObjectTwo = new MyObjectTwo() { Name = "Notebook", Price = 100, ReferenceId = myVal };
context.MyObjectTwos.Add(myObjectTwo);
context.SaveChanges();
transaction.Commit();
}
catch (Exception ex)
{
}
}
}
|
|
|
|
|
Probably not much, but pay attention to the documentation:
Dispose should rollback the transaction. However, the behavior of Dispose is provider specific, and should not replace calling Rollback .
In other words, the using block should roll-back the transaction if you haven't called Commit ; but different database providers might not implement that correctly, and might require you to explicitly call Rollback .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hello,
I can not understand how to set the timeout of a .net 6.0 web api application.
In the .net 4.8 application I set the executionTimeout parameter of the httpRuntime section in the web.config.
Is there anyone who can help me?
Thank you.
|
|
|
|
|
You need to change the requestTimeout property on the aspNetCore element instead:
="1.0"="utf-8"
<configuration>
<system.webServer>
<aspNetCore requestTimeout="00:02:00" .../>
</system.webServer>
</configuration>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey everyone!
I have a Silverlight application I want to salvage.
I have no intention of rewriting (no chance I will trash all the work I've done on the code over the years).
Any solutions or alternatives you'd recommend?
|
|
|
|
|
OpenSilver is a modern, plugin-free, open-source reimplementation of Silverlight. It uses WebAssembly to bring back the power of C#, XAML, and .NET to client-side Web development.
Having never jumped on the Silverlight bandwagon, I haven't tried this, so I can't tell you whether it will work with your current code. But it's probably the simplest place to start.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
headres---area,sub-area,alpha-A,alpha-B,
data------windows,cmd,output,result,
windows,cmd,output,false
windows,cmd,output,false
windows,cmd,output,result
linux,terminal,output,result
linux,terminal,output,false
linux,terminal,output,flase
think this is csv file there is 4 headers
now i want sort this data and i want a only result in both area..(or)
then if i want to take a area i will choose windows then sub area cmd then alpha-A is output the alpha-B is only result i want print only that result and it store in another file
|
|
|
|
|
Well, go ahead; you have our permission to do that.
Feel free to come back if you have an actual question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
WithDegreeOfParallelism: Degree of parallelism is the maximum number of concurrently executing tasks that will be used to process the query.
I don't quite understand what you mean by this sentence. --> "concurrently executing tasks"
What exactly is meant by "TASK"? CPU or Kernel or something else???
What does "3" do in the code block below;
AdventureWorks2017Context context = new AdventureWorks2017Context();
context.Products.AsParallel().WithDegreeOfParallelism(3).ForAll(p =>
{
//ToDO
})
Best Regards...
|
|
|
|
|
dataminers wrote: what you mean by this sentence. --> "concurrently executing tasks" The term tasks in that context is equivalent to threads in your previous question. LINQ will create multiple threads and share the problem between them.
dataminers wrote: What does "3" do in the code block below; It's the value referred to in your first sentence.
|
|
|
|
|
Dear Richard, thank you for your reply.
I understand that based on your answer, the two code blocks below are the same;
await Task.Run(() =>
{
CalculateSomething(5);
});
await Task.Run(() =>
{
CalculateSomething(8);
});
List<int> myList = new() { 5, 8 };
myList.AsParallel().WithDegreeOfParallelism(2).ForAll(x =>
{
CalculateSomething(x);
});
Both complete the process on two Threads.
Note: CalculateSomething hypothetically this function takes a very long time
Regards...
modified 9-Sep-22 17:15pm.
|
|
|
|
|
That certainly makes sense.
|
|
|
|
|
Sometimes people get confused when you read a lot. You know, not all information on the Internet is correct. That's why I'm investigating the issue. Please don't get me wrong.
Multi-Thread: Running more than one Threads inside a Process.
Parallel Programming: Running threads simultaneously on different cores in multi-core processors.
So; .NET Core TPL (Task Parallel Library) is Multi-Thread programming, not a Parallel Programming.
Isn't it?
|
|
|
|
|
Your definitions are not correct. You can also have multiple physical CPUs with multiple cores each.
Threads refers to "threads of execution". You can have multiple threads running on a single core, though the core will only execute code on one thread at a time, for a limited amount of time before switching to the next thread in the scheduler. You can have multiple cores running multiple threads at the same time. You can have more threads "running" than there are cores in the CPUs to run them. For example, open Task Manager and go to the Performance tab. See the "Threads" number? There's thousands of threads running in hundreds of processes, but you only have, say, 8 cores to run them all. Most threads are sitting idle, waiting for a core to execute them, or waiting for I/O to complete, or whatever else.
Windows gives the illusion of running thousands of threads using "pre-emptive multitasking". This allows a thread to execute on a core for a small amount of time before being stopped and the core switches to the next thread in the scheduler.
A Task is NOT a thread. In some respects, it looks like a thread of execution, but it's really an abstraction, or wrapper around a block of work to do. Tasks are scheduled to run on a pool of threads (a ThreadPool). You can have more tasks running than there are threads in the pool. Tasks can sit idle waiting for an available thread to a task, or part of a task.
A single task can be executed by multiple threads. Thread0 can execute a task for a limited time, then the task is idled, waiting for execution to be resumed by either another thread, or the same thread that was executing it before. Thread1 can pick up where Thread0 left off, or Thread0 can come back around and pick up where it left off.
Think of it as layers, with CPUs at the bottom of the stack, cores on top of that, then threads on top of cores, and Tasks on top of threads. Each layer you go higher in the stack can have more items in it than the layer below.
|+++++++ Tasks +++++++|
|++++ Threads ++++|
|+++ Cores +++|
|+ CPUs + |
Parallel programming is a technique, or library, that makes it easier to write code to execute on multiple threads, or cores, to accomplish work. The Task Parallel Library is an IMPLEMENTATION of parallel programming. The TPL makes it easier to write code that uses multiple threads to accomplish work.
|
|
|
|
|
dataminers wrote: the two code blocks below are the same
No they're not.
The first one starts a new task to execute CalculateSomething(5) , and then suspends the current thread until that task completes. It then starts another task to execute CalculateSomething(8) .
The second one starts two tasks to execute CalculateSomething(5) and CalculateSomething(8) , and then freezes the current thread until both have completed.
If you time both approaches, the AsParallel code will be roughly twice as fast as the two await Task.Run(...) calls.
The closest equivalent using Task.Run would be:
Task t1 = Task.Run(() => CalculateSomething(5));
Task t2 = Task.Run(() => CalculateSomething(8));
await Task.WhenAll(t1, t2);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is it possible to run multi-threads on a single-core processor?
Best Regards...
|
|
|
|
|
Yes, you can spawn multiple threads on single core system. Processor with swap between threads based on priority and that will give an illusion of multithreaded processing.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
|
|
Yes. Under Windows, it's been that way since the dawn of Windows 2.1, back in, what, 1988-ish?
Today, you can just open Task Manager, click on the Performance tab, and the CPU tab on the left. See the "Threads" number? See the "Core" and "Logical processors" numbers? How else are you going to get thousands of threads running on so few processors?
|
|
|
|
|
No one I know had a quad-core i386
Still, didn't want to be that blunt.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|