Affinity New Dual core PC
Hi
I recently developed a serial port terminal program, using the standard C# SerialPort class etc on an old intel P4 computer. Everything runs fine. We have upgraded out PCs to dual core Intels, and now when I run the program, after an unspecified time, the program comes up with AccessViolationException was unhandled "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.". If I run the program, and go into task manager and disable one of the cores on the affinity tab, all runs fine and the program runs for hours.
Is there any way for me to fix this without turning a core off as surely this should be possible? but if I do need to turn a core off, can I do it with code instead of using Task Manager> I have done this before on a c++ program using SetProcessAffinityMask(hProcess ,1); but can't find the equivalent in C#
I have included the stack trace below
TIA
MartinPosted Aug 1, 2007, 4:33 AM
[
DllImport("kernel32.dll")] static extern bool SetProcessAffinityMask(IntPtr hProcess, UIntPtr dwProcessAffinityMask);IntPtr
handle = (IntPtr)Process.GetCurrentProcess().Handle; UIntPtr affinityMask = new UIntPtr((uint)1); Console.WriteLine("Handle {0}, Mask{1}", handle, affinityMask); if (!SetProcessAffinityMask(handle, affinityMask)) MessageBox.Show("Error code: " + Marshal.GetLastWin32Error());MartinPosted Jul 31, 2007, 7:10 AM
Heres the stack sorry that it makes it quite unreadable when I post it................. ]
System.AccessViolationException was unhandled Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TextBoxBase.WndProc(Message& m) at System.Windows.Forms.RichTextBox.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at Terminal.Program.Main() in C:\Projects\Strat_Res\Terminal\Terminal\Program.cs:line 17 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()