Solved

Very long process (DataAdapter.Update), how to avoid ContextSwitchDeadlock (without simply disabling the exception)? (Urgent!)

Posted on 2006-06-25
6
651 Views
Last Modified: 2011-09-20
I have 16 commands like this:

OleDbDataAdapter.Update(DataTable);

and each one is trying to insert about 10,000 rows to a Microsoft Access 2000 table.

So for sure, I will get the ContextSwitchDeadlock exception while debugging.

My question is how to make my application as optimized as possible to avoid throughing this exception without simply disabling it from the Debug --> Exceptions --> Managed...

And by the way, does the Release Build of the appplication will through the same exception while running?

Thanks in advance
0
Comment
Question by:salan_alani
  • 3
  • 3
6 Comments
 
LVL 41

Expert Comment

by:graye
ID: 16980920
This error typically occurs while running with the debugger...   This is a new "feature" in Visual Studio 2005 that is universally hated by all.  OK, perhaps that's just my opinion :)

To turn off this rather annoying error, simply change a setting from the Debug menu.  Click on the Exceptions menu item to lauch a menu.  Drill into "Managed Debugging Assistants" and uncheck "ContextSwitchDeadlock"
0
 
LVL 2

Author Comment

by:salan_alani
ID: 16981719
I know how to turn this feature off and I already mentioned that in my post. What I want is how to make my application as optimized as possible to avoid throughing this exception. In other words, how to meet all the rules that avoid detecting the deadlock. For example, how to use the pumping window or how to use the threading in my application where I am using a 16 commands like this:

OleDbDataAdapter.Update(DataTable);

and each one is trying to insert about 10,000 rows to a Microsoft Access 2000 table.
0
 
LVL 41

Expert Comment

by:graye
ID: 16983963
So, you're comfortable with the fact that you're not really dealing with an error...  and are really just trying to optimize your code.

Aside from the fact that the process takes a lot of time, it's also probably consuming a lot of memory.  So breaking up the Updates into more managable chunks will solve the "so-called" error and also reduces the memory footprint.

One of the features that's new to the Dot Net Framework 2.0 is the ability to perform a Fill() incrementally.  This allows you to process the updates in sizable chunks (rather than all rows at once).  Here is a short (partial) code snippet to demonstrate the technique that I use

                    ' Since some tables can be quiet large, we break them up
                    ' into smaller chunks.
                    For i = 0 To row_count Step max_rows
                        dts(0).Clear()
                        da.Fill(i, max_rows, dts)
                        ' mark the rows as "Added"
                        for each dr in dts(0).Rows
                            dr.SetAdded()
                        Next
                        da.Update(dts(0))
                    Next

If you need more speed than that, then I'd consider using the "classic" ADO drivers for Microsoft Access.  They are connection-based rather than the disconnected model of ADO.Net.  In extreme cases with over a half million rows for a single table, I've used both techniques... the incremental fill and "classic" ADO

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Author Comment

by:salan_alani
ID: 16984582
Thanks graue, it's a great idea. But could you tell me approximately what is the max_rows value that I should use for a normal speed PC (INTEL P4 1.7 GHz, 256 KB Cache Memory, 512 MB RAM, Windows 2000 Server Edition, ...). Although my tables have approximately 30 columns for each one. Or if there is a special way to calculate this value, or if it is possible to tell me the value that you used with your projects, so I could have an idea about how big/small the value is.

Regarding the classic ADO drivers for MS Access, I really don't have any idea on how to use it. So, do you have any article links on this subject to learn it and see if it will help me increasing the speed of my application.

The thing that my application is taking almost all the CPU and Memory usage, and I am trying to optimize it as much as possible. So I am waiting for your feedback please..

Thanks for your help..
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 16985570
Actually, I just experiment by watching the memory values in the Task Manager to pick a max_rows value.   For my example above where I have ~600,000 rows in a single table, I use 10,000 as the max_rows value.

I've just recently posted a beta version of a program that uses this technique, if you'd like to see the whole thing in action.  It uses both techniques as I've described above (incremental fills and classic ADO).

The VB.Net source code is for an entire suite of programs (only one of which, called BackupSOSOS, will be of interest to you... the other 95% of the suite you can disregard).   You're welcome to take a look and copy/paste bits and pieces (or the whole thing).

http://home.hot.rr.com/graye/Temp/SOSOSv3_Beta
0
 
LVL 2

Author Comment

by:salan_alani
ID: 16995995
It was really great help, thank you very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Object Oriented Best Practice 5 35
Setting location of a form 4 22
C# code editing and collaboration 3 49
Open a word document 23 19
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now