Set processor affinity with vb.net

LeeLiam
LeeLiam used Ask the Experts™
on
We have a VB.Net application using an Access database. We have added several background tasks. This seems to work fine on most computers. However, one customer said all of their Core i5 and i7 computers were experiencing slowness. Finally, they said they solved the problem by setting the processor affinity from all cores to just one core. This seems counter-intuitive to me. It seems fewer cores would cause more slowness.

Is it possible this is a good solution? If so, what is the best way to program the application to use one core?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015

Commented:
Access is not designed for multiple simultaneous accesses. It cannot process a request from one of the cores while another one is using it. It just pile up requests in queue and process them one after another.

So using an Access database with multiple cores gives you no advantage, but bogs down the whole thing because of the extra overhead encountered by the different cores to manage concurrency on the database access.

Many programmers think that 64-bit, multicore, multithread and asynchrone methods solve all the problems. But as long as an application is dealing with another one that was not built with these in mind, you often make things worse by using a new technology with older software.
Try this create a startup app that calls your app thru process start:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myProc As Process = Process.Start("Path_to_application\myapp.exe") : myProc.ProcessorAffinity = CType(1, IntPtr) : End
me.close
    End Sub
' the 1 is the processor to use 1=CPU0, 2=CPU1, etc

Author

Commented:
Does this mean there is no way to put something in the code of the original VB.Net application that can set the processor affinity when it is launched? It seems strange the .Net Framework doesn't have something to handle this.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Top Expert 2015

Commented:
.NET can, but the Access database engines, either JET or ACE are not multicore, and when you work with Access, you are working with that engine. And as far as I know, a unique engine processes all the calls on a given computer.

Author

Commented:
Maybe I was misunderstood. Is it possible, using VB.Net code, to set the processor affinity from the default of all cores so the application will use only a single core?
Top Expert 2015
Commented:
You do not set the affinity to "one core", you set it to a specific core, which is not exactly the same thing.
 
System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = New IntPtr(1)

The value you pass to IntPtr is the core you want to use, and is a bit on mask, where 1 is processor 0, 2 is processor 1, 4 is 2, 8 is 4 and so on.

Author

Commented:
Perfect. Thanks.

Author

Commented:
Exactly what I needed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial